随机数值小游戏 这样写怎么简化啊
import randomanswer = random.randint(1,10)
i = 3
temp = input('请你猜猜我现在心中想的是那个数字:')
while i > 1 :
i = i - 1
if temp.isdigit() == 0:
print('输入内容不合法,',end='')
temp = input('请输入一个整数:')
else:
guess = int(temp)
if guess>0 and guess <= 10:
if guess == answer and i == 2:
print('你是我肚子里的蛔虫吗!')
print('不过答对了也没有奖励哦!')
break
elif guess == answer and i != 2:
print('不错,答对了!')
break
elif guess > answer:
print('大了大了,',end='')
temp = input('再给你一次机会:')
else:
print('小了小了,',end='')
temp = input('再给你一次机会:')
else:
print('输入不合法,',end='')
temp = input('请输入0-10之间的整数:')
iftemp.isdigit() == 0:
print('输入内容不合法,不过没机会了!')
else:
guess = int(temp)
if guess == answer and i == 1:
print('机会把握住了,答对了!')
elif guess == answer and i != 1:
None
else:
print('很可惜,没机会了!')
print('game over') import random
answer = random.randint(1,10)
i = 3
temp = input('请你猜猜我现在心中想的是那个数字:')
while i > 1 :
i = i - 1
if temp.isdigit() == 0:
print('输入内容不合法,',end='')
temp = input('请输入一个整数:')
else:
guess = int(temp)
if guess>0 and guess <= 10:
if guess == answer and i == 2:
print('你是我肚子里的蛔虫吗!')
print('不过答对了也没有奖励哦!')
break
elif guess == answer and i != 2:
print('不错,答对了!')
break
elif guess > answer:
print('大了大了,',end='')
temp = input('再给你一次机会:')
else:
print('小了小了,',end='')
temp = input('再给你一次机会:')
else:
print('输入不合法,',end='')
temp = input('请输入0-10之间的整数:')
iftemp.isdigit() == 0:
print('输入内容不合法,不过没机会了!')
else:
guess = int(temp)
if guess == answer and i == 1:
print('机会把握住了,答对了!')
elif guess == answer and i != 1:
None
else:
print('很可惜,没机会了!')
print('game over') 本帖最后由 jackz007 于 2021-7-15 13:55 编辑
import random
answer = random . randint(1,10)
t = 3
print('请你猜猜我现在心中想的是那个数字')
print('你总共有', t , '次机会')
for i in range(t):
while True:
print()
temp = input('请输入一个整数:') . strip()
if temp:
try:
guess = int(temp)
break
except:
print('输入不合法!')
else:
break
if temp:
if guess == answer:
if i == 0:
print('你是我肚子里的蛔虫吗!')
print('不过答对了也没有奖励哦!')
else:
print('不错,答对了!')
break
else:
if guess > answer:
print('大了大了,' , end = '')
else:
print('小了小了,' , end = '')
if i < t - 1:
print('再给你一次机会')
else:
break
else:
print('很可惜,没机会了!')
print('game over') jackz007 发表于 2021-7-15 13:53
刚开始学 谢谢指教{:5_109:}
页:
[1]