想在某一行加一个条件请问如何实现
本帖最后由 reflex 于 2020-10-25 13:19 编辑如下:
import random
secret = random.randint(1,10)
guess = 0
times = 3
print('----------------------------------------')
print('猜一猜我心里想的是哪个数字:',end = ' ')
while (guess != secret) and times > 0:
temp = input()
if temp.isdigit():
guess = int(temp)
if guess == secret:
print('牛逼,你猜对了!')
print('不过没有奖励!')
else:
if guess > secret:
print('往小了猜!')
else:
print('往大了猜!')
if times > 1:
print('你还有',times - 1,'次机会,再猜:',end = '')
else:
print('机会用光!')
else:
print('输入格式有误,还有',times -1,'次机会,请输入一个整数:',end = '')
times = times - 1
print('游戏结束!')
想在第24行加个条件 times > 1 请问如何修改 elif xxxxxx 2269099035 发表于 2020-10-25 13:41
elif xxxxxx
涨姿势了,谢谢
import random
secret = random.randint(1,10)
guess = 0
times = 3
print('----------------------------------------')
print('猜一猜我心里想的是哪个数字:',end = ' ')
while (guess != secret) and times > 0:
temp = input()
if temp.isdigit():
guess = int(temp)
if guess == secret:
print('牛逼,你猜对了!')
print('不过没有奖励!')
else:
if guess > secret:
print('往小了猜!')
else:
print('往大了猜!')
if times > 1:
print('你还有',times - 1,'次机会,再猜:',end = '')
else:
print('机会用光!')
elif times > 1:
print('输入格式有误,还有',times -1,'次机会,请输入一个整数:',end = '')
times = times - 1
print('游戏结束!')
----------------------------------------
猜一猜我心里想的是哪个数字: s
输入格式有误,还有 2 次机会,请输入一个整数:s
输入格式有误,还有 1 次机会,请输入一个整数:s
游戏结束!
页:
[1]