Python猜数字游戏

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 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")

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


Python猜数字游戏_第1张图片
pyzao.jpg

你可能感兴趣的:(Python猜数字游戏)