Python学习记录-2016-12-13
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习记录-2016-12-13相关的知识,希望对你有一定的参考价值。
今日学习记录:
While循环。
For循环。
While基本语法:
count = 0 While True: print(count, "-----") count +=1 if count = 100 break
For基本语法:
for i in range(0, 10, 2): print(i, "-----") for g in range(10) print(g) if g > 5: break
示例猜测年龄:
age = 30 count = 0 while true: guessage = int(input("guess age:")) if guessage > 30: print("think smaller") elif guessage == 30: print("configratulations! you got it!") break else: print("think bigger") count +=1 if count == 3: continue_confirm = input("do you want to continue?") if continue != "n": count = 0
优化:
age = 30 count = 0 while count < 3: guessage = int(input("guess age:")) if guessage > 30: print("think smaller") elif guessage == 30: print("configratulations! you got it!") break else: print("think bigger") count +=1 if count == 3: continue_confirm = input("do you want to continue?") if continue != "n": count = 0
For循环这个示例:
age = 30 for i in range(3): guessage = int(input("guess age:")) if guessage > 30: print("think smaller") elif guessage == 30: print("configratulations! you got it!") break else: print("think bigger") else: print("you have tried too many times...fuck off.")
以上是关于Python学习记录-2016-12-13的主要内容,如果未能解决你的问题,请参考以下文章
[未解决问题记录]python asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')(代码片段
ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段