Python猜数字游戏

2018-09-26  本文已影响0人  小火车托马斯

import random
secret=random.randint(1,10)#生成1到10的整型随机数

print("-----------------Guess number game------------------")
temp=input("Please input a number,you have 3 chances in total:")
number=int(temp)
chance = 2
if number==secret:
print("awesome,you got the anwser 1st time")
print("congratulations")
else:
while chance>0 or number==secret:
if number<secret:
print("too small, " + "you only have " + str(chance) + " chance now")
elif number>secret:
print("too big, " + "you only have " + str(chance) + " chance now")
else :
print("congratulations")
break
chance = chance - 1
temp = input("Please input a new number:")
number = int(temp)
print("Game Over")

=============


pyzao.jpg
上一篇 下一篇

猜你喜欢

热点阅读