判断3次,猜年龄
方法一
1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3 4 count = 0 5 while count < 3: 6 guess_age = int(input("age:")) 7 if age_of_zhuyouen == guess_age: 8 print("age is ok") 9 break10 elif age_of_zhuyouen > guess_age:11 print("age is small")12 else:13 print("age in large")14 count +=115 else:16 print("you have test too many times,fuck off..")
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess.pyage:35age is ok
方法二
1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3 4 for i in range(3): 5 guess_age = int(input("age:")) 6 if age_of_zhuyouen == guess_age: 7 print("age is ok") 8 break 9 elif age_of_zhuyouen > guess_age:10 print("age is small")11 else:12 print("age in large")13 else:14 print("you have test too many times,fuck off..")
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess_for.pyage:23age is smallage:23age is smallage:35age is ok
方法三
1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3 4 count = 0 5 while count < 3: 6 guess_age = int(input("age:")) 7 if age_of_zhuyouen == guess_age: 8 print("age is ok") 9 break10 elif age_of_zhuyouen > guess_age:11 print("age is small")12 else:13 print("age in large")14 count +=115 if count == 3:16 confirm_input = input("do you want input guess again..")17 if confirm_input != "quit":18 count = 0
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess任意.pyage:1age is smallage:1age is smallage:1age is smalldo you want input guess again..quit
自增加10
1 # author = "zhuyouen" 2 3 count = 0 4 while True: 5 print("count:",count) 6 count +=1 7 if count == 10: 8 break 9 10 11 12 #for i in range(10):13 # print("loop",i)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/while.pycount: 0count: 1count: 2count: 3count: 4count: 5count: 6count: 7count: 8count: 9
1 # author = "zhuyouen" 2 ''' 3 count = 0 4 while True: 5 print("count:",count) 6 count +=1 7 if count == 10: 8 break 9 '''10 11 12 for i in range(10):13 print("loop",i)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/while.pyloop 0loop 1loop 2loop 3loop 4loop 5loop 6loop 7loop 8loop 9