猜数字游戏_Python

 预先设置数字变量

age_of_test =  25 #这里设置为25,也可随意


guess_age = int (input("guess age:"))

if guess_age == age_of_test :
print("Yes, you got it!") #判断正确后打印 Yes,you got it! 并继续执行命令
elif guess_age > age_of_test:
    print("think smaller...")  #判断数字小于预定值时 提示!
else:
print("think bigger!") # 上面所有条件不成立时打印此语句!

循环实例1.
count = 0
while True:
if count ==2:
break
guess_age = int(input("guess age:"))
if guess_age == age_of_test :
print("Yes, you got it!")
break #判断正确打印后,输出语句并结束整个循环
elif guess_age > age_of_test:
print("think smaller...") #判断数字小于预定值时 提示!
   else:
     print("think bigger!")
    count +=1
   if count ==2: #判断上列程序连续错误三次是否还要继续
      countie_confirm = input("do you want to keep guessing..?")
  if countie_confirm != 'n': #判断输入字段是否为"n",不为n则重置计数器
  count = 0
 

猜你喜欢

转载自www.cnblogs.com/Shuyi/p/11553304.html