美文网首页
Python猜数字游戏

Python猜数字游戏

作者: 小火车托马斯 | 来源:发表于2018-09-26 00:21 被阅读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

相关文章

网友评论

      本文标题:Python猜数字游戏

      本文链接:https://www.haomeiwen.com/subject/fobroftx.html