使用Python编的猜数字小游戏
作者:互联网
1 import random 2 3 secret = random.randint(1, 30) 4 guess = 0 5 tries = 0 6 7 print("我叫丁丁,我有一个秘密数字!") 8 print("数字从1到30,你只有6次机会!") 9 10 while int(guess) != secret and tries < 6: 11 print("你猜的数字是?") 12 guess = input() 13 if int(guess) < secret: 14 print("数字太小了!再猜!") 15 elif int(guess) > secret: 16 print("数字太大了!再猜!") 17 tries = tries + 1 18 if int(guess) == secret: 19 print("你真厉害!恭喜你猜对啦!") 20 else: 21 print("你猜错6次啦,下次再玩吧!") 22 print("我的秘密数字是:", secret)
标签:guess,数字,Python,tries,int,secret,小游戏,print 来源: https://www.cnblogs.com/rancher-maomao/p/10587455.html