while循环 age_of_Jim = 56
count = 0 #开始计数 while True: #循环代码 if count ==3:#如果次数=3 break#退出 guess_age = int(input("guess age:"))#int-->字符串转换数字 if guess_age == age_of_Jim:#如果猜的数字=Jim年龄 print("yes you got it.")#打印“yes you got it.” break #猜对了退出 elif guess_age > age_of_Jim :#如果猜的数字>Jim年龄
print("think smaller...")#打印“think smaller....”
else: #否则 print("think bigger!") #打印think bigger!
count +=1 #尾部计数=count +1 if count ==3: # 另加语言,如果次数=3 print("you have tried too many times....goodbye")#打印....
for循环
age_of_oldboy = 56#定义年两=56
count = 0 #头部计数
for i in range(3):#循环次数 if count ==3:#如果次数=3 break#退出 guess_age = int(input("guess age:"))#输入guess age: if guess_age == age_of_oldboy:#如果猜的年龄=定义数 print("yes you got it.")#打印yes you got it. break elif guess_age > age_of_oldboy:#如果猜的年龄>定义数 print("think smaller...")#想的小一点 else:#否则 print("think bigger!")#想的大一点 count +=1#尾部计数if count ==3:#如果次数超过3 print("you have tried too many times..Goodbye")#打印你试的次太多了