首页 > 代码库 > Python学习记录-2016-12-13
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。