《改进小游戏》那一篇的游戏,怎么限制次数?
代码如下:import random
答案 = random.randint(1,100)
print("欢迎来到猜数字小游戏!")
print("答案是1~100之间随机的一个数!")
temp = input("现在请输入一个数:")
guess = int(temp)
if guess == 答案:
print("猜对啦!")
print("然而并没有奖励")
else:
if guess > 答案:
print("哎呀,大了大了")
else:
print("哎呀,小了小了")
while guess != 答案:
temp = input("猜错啦!继续吧!加油!")
guess = int(temp)
if guess == 答案:
print("猜对啦!")
print("然而并没有奖励!")
else:
if guess > 答案:
print("哎呀,大了大了!")
else:
print("哎呀,小了小了!")
怎么限制答题的次数?萌新第一次写,求助 还有,总觉得代码太长了萌新第一次学只会这么点,请问一下如何缩短? 帮你顶一下啊 import radmod
secret = radmod.radint(1.10)
print('欢迎游玩数字小游戏')
tem = input('来猜猜我心里面的数字是什么?:')
guess = int(tem)
ls = 1
while ('guess = secret') and (ls < 3):
if guess == secret:
print('厉害厉害")
else:
if guess > secret
print('大了')
else:
print('小了')
tem = input('再给你一次机会')
guess = int(tem)
ls = ls+1
if guess == secret:
print('恭喜你,猜中了!')
if (guess != secret) and (ls == 3):
print('你是沙雕么?')
print('游戏结束')
我也是新手其中应该还有bug,不过这样能限制3次
qq2663147776 发表于 2019-4-30 20:06
import radmod
secret = radmod.radint(1.10)
print('欢迎游玩数字小游戏')
感谢 啊!改完了!
import random
答案 = random.randint(1,10)
print("欢迎来到猜数字小游戏!")
print("答案是1~10之间随机的一个数!")
temp = input("现在请输入一个数:")
guess = int(temp)
次数 = 0
while ("guess != 答案") and ("次数 > 3"):
if ("guess == 答案") and (次数 < 3):
if guess == 答案:
print("恭喜你!答对啦!游戏结束!")
else:
if guess > 答案:
print("哎呀,大了大了")
else:
print("哎呀,小了小了")
temp = input("看在你这么帅的份上,再给你一次机会!")
guess =int(temp)
次数 = 次数+1
if guess == 答案:
print("恭喜你!终于猜对啦!")
if (guess != 答案) and (次数 == 3):
print("你好蔡啊")
print("游戏结束")
感谢楼上那位……不过不得不说楼上那位好多错误
我去,刚发完发现了几个错误 依旧是看不懂 算我还是有点天赋
不用凑够10分
我猜懂了
print('Guessing Game')
temp = input('Guess a number!?')
guess = int(temp)
ls = 1
while (guess != 8) and (ls < 3):
guess = int(temp)
if guess == 8:
print('u got it')
else:
if guess > 8:
print('smaller')
else:
if guess < 8:
print('bigger')
temp = input('One more try!?')
ls = ls + 1
if ls == 3:
print ('game over')
终于!改完了!
import random
yes = random.randint(1,10)
guess = 0
ls = 0
print("欢迎来到猜数字小游戏!")
while (guess != yes) and (ls < 3):
guess = int(input("请输入一个数字"))
if guess == yes:
print('答对了')
elif guess > yes:
print('大了')
elif guess < yes:
print('小了')
ls = ls + 1
if ls == 3:
print ('三次过了') import random
secret = random.randint(1,10)
temp = input ('猜猜我现在想着的数字是什么:')
guess = int(temp)
if guess == secret:
print('哇!太厉害了,一次就能猜中!')
else:
i=0
while guess != secret and i < 3:
if guess > secret :
print('太大啦!')
else:
print('太小啦!')
temp = input('再来一次吧!你还有'+str(3-i)+'次机会哦!')
guess = int(temp)
i = i + 1
if guess == secret:
print ('太棒了!这次猜对啦!')
if i == 3:
print('唉……')
print ('下次再来玩吧~')
分享一下我的作业
页:
[1]