使用Python编的猜数字小游戏
作者:互联网
import random secret = random.randint(1, 30) guess = 0 tries = 0 print("我叫丁丁,我有一个秘密数字!") print("数字从1到30,你只有6次机会!") while int(guess) != secret and tries < 6: print("你猜的数字是?") guess = input() if int(guess) < secret: print("数字太小了!再猜!") elif int(guess) > secret: print("数字太大了!再猜!") tries = tries + 1 if int(guess) == secret: print("你真厉害!恭喜你猜对啦!") else: print("你猜错6次啦,下次再玩吧!") print("我的秘密数字是:", secret)
标签:guess,数字,Python,tries,int,secret,小游戏,print 来源: https://blog.51cto.com/10321203/2368063