首页 cheatsheet-python-grok

cheatsheet-python-grok

举报
开通vip

cheatsheet-python-grokGROKLEARNINGcelsius=int(input('Temp.inCelsius:'))AsktheuserforatemperatureindegreesCelsiusfahrenheit=celsius*9/5+32Calculatetheconversionprint(farenheit,'Fahrenheit')OutputtheresultPuttingittogether:CelsiustoFahrenheitconverter'e'inmsgI...

cheatsheet-python-grok
GROKLEARNINGcelsius=int(input('Temp.inCelsius:'))AsktheuserforatemperatureindegreesCelsiusfahrenheit=celsius*9/5+32Calculatetheconversionprint(farenheit,'Fahrenheit')OutputtheresultPuttingittogether:CelsiustoFahrenheitconverter'e'inmsgIsacharacterinastring?'ell'inmsgIsastringinanotherstring?msg.upper()Converttouppercasemsg.count('l')Countacharacterinastringmsg.replace('l','X')Replaceacharacterorstringmsg.replace('l','')Deleteacharacterorstringifmsg<'n':print('a-m')else:print('n-z')Lessthananotherstring?⚠stringsarecomparedcharacteratatime(lexicographicorder)msg='hello'ifmsg=='hello':print('howdy')ComparetwostringsStringmanipulationalsolowerandtitlemsg.islower()Isthestringalllowercase?alsoisupperandistitlerange(10)Countfrom0to9range(1,11)Countfrom1to10range(10,0,-1)Countfrom10downto1range(0,11,2)Count2atatimeto10range(10,0,-2)Countdown2atatimeforcin'Hello':print(c)Repeatablockoverastringforcin'Hello':print(c,end='')print('!')Keepprintingononelinemsg='IgrokPython!'foriinrange(len(msg)):print(i,msg[i])Repeatablockoverlist(orstring)indicesforiinrange(10):print(i)Repeatablock10timestotal=0foriinrange(10):total=total+iprint(total)Sumthenumbers0to9Repeatablock(afixednumberoftimes)⚠rangestartsfrom0andgoesupto,butnotincluding,10x==3Aretwovaluesequal?TrueFalseTheanswerisaBoolean:orx!=3Aretwovaluesnotequal?x<3Lessthananother?x>3Greaterthananother?x<=3Lessthanorequalto?x>=3Greaterthanorequalto?mark=80ifmark>=65:print('credit')elifmark>=50:print('pass')else:print('fail')Decidebetweenmanyblocks‣elifcanbeusedwithoutelse‣elifcanbeusedmanytimesmark=80ifmark>=50:print('pass')else:print('fail')Decidebetweentwoblocksx=3ifx==3:print('xis3')Decidetorunablock(ornot)Decidebetweenoptions⚠twoequalssigns,notone365+1-2Additionandsubtraction25*9/5+32Multiplicationanddivision2**8Powers(2tothepowerof8)str(365)ConvertintegertostringWholenumbers(integers)celsius=25Creatingavariablecelsius*9/5+32UsingavariableVariables'perfect'Singlequoted"credit"Doublequoted'Hello'+'World'Add(concatenate)strings'Echo...'*4Multiplystringbyintegerlen('Hello')Lengthofastringint('365')Convertstringtointeger'''Hello,World!'''Multi-lineText(strings)print('Hello,world!')Printamessagename=input('Whatisyourname?')Askingtheuserforastringnum=int(input('Enteranumber:'))Askingtheuserforawholenumber(aninteger)ndays=365print('Thereare',ndays,'inayear')Printmultiplevalues(ofdifferenttypes)Interactwiththeuser(inputandoutput)s=[datetime.hs.insert(0,lambf__init__(self,formatself.format=formatdef__getitem__(self,i):funcs=self._months[i]ifisinstance(i,slice)return[f(self.forelse:returnfuncs(seln__(self):LearnmoreinIntro.toProgramming@groklearning.comPython3cheatsheet(thebasics)
本文档为【cheatsheet-python-grok】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_642352
暂无简介~
格式:pdf
大小:124KB
软件:PDF阅读器
页数:1
分类:互联网
上传时间:2018-03-21
浏览量:27