这种改进如何改进呢~
print("欢迎进行python文字的第三次文字游戏改进测试")temp = input("please fall a number in the bank")
guess = int(temp)
while guess != 8:
chance = 3
chance = chance -1
if guess >8:
print("bigger than answer")
else :
print("smaller than answer")
temp = input("please try again ")
guess =int(temp)
print("you are right")
input("The game is over!")
while chance == 0:
print("sorry, you have 3 times to answer this question")
input("the game is over")
英语有点烂,不要介意。
我想让chance = 0的时候,就结束这个游戏,
但是 好像while 一直重复的时候,会反复运行chance = 3
这就会导致一直退不出去。 print("欢迎进行python文字的第三次文字游戏改进测试")
temp = input("please fall a number in the bank")
guess = int(temp)
chance = 2
while chance != 0:
if guess >8:
print("bigger than answer")
elif guess <8:
print("smaller than answer")
else:
break
temp = input("please try again ")
guess =int(temp)
chance = chance -1
if guess != 8:
print("sorry, you have 3 times to answer this question")
else:
print("you are right")
print("The game is over!") 冬雪雪冬 发表于 2019-6-2 19:55
谢谢大佬,原来要先做一个while的机会语句。 import random
#获取1-30的随机数quession
quession = random.randint(1,30)
#定义while循环标记
active = True
while active:
#定义次数计数器
for i in range(6,0, -1):
#获取用户输入
answer = int(input("请输入1-30的整数回答问题:"))
print('目前还有%d次猜测机会!' % i)
if answer > quession:
print("猜大了,请努力")
elif answer < quession:
print("猜小了,请努力")
elif answer == quession:
print("真棒,回答正确!正确答案为%d ." % quession)
#如果用户回答正确,重置while标记退出循环
active = False
break
#猜测次数用完后,判断用户是否想继续游戏
else:
count = input("目前已经没有回答机会,请问是否放弃游戏:")
if count == "n":
continue
else:
break
这是我的猜数代码,有兴趣可以参考下
页:
[1]