当我键入play
时,一个随机数被分配给number1
. 它要求我进行预测,然后我输入一个数字,比如说 5。输入 5 后,我总是得到else
陈述而不是if
陈述。我什至放了一个print()
来找出生成的数字。有时我在 1 以内或在 1 以内(游戏也允许在 1 以内),但它仍然将我重定向到else
声明。有人可以帮忙吗?谢谢。
money = 1000000
def luckyrollgame():
global money
from random import choice
print('You are in the game lobby of Lucky Roll.')
print('Choose either \'rules,\' \'play,\' or \'back\'')
lobby = input()
if lobby == 'rules':
luckyrollgamerules()
if lobby == 'play':
die = [1, 2, 3, 4, 5, 6]
number1 = choice(die)
prediction = input('Please type your prediction number: ')
if prediction == number1:
print('Good job! You guessed right!')
money = money + 3
print('You now have ' + str(dollars) + 'dollars.')
if prediction == number1 - 1:
print('Good job! You guessed right!')
money = money + 3
print('You now have ' + str(dollars) + 'dollars.')
if prediction == number1 + 1:
print('Good job! You guessed right!')
money = money + 3
print('You now have ' + str(dollars) + 'dollars.')
else:
print('I\'m sorry. You didn\'t get the number right.')
print('The number was ' + str(number1) + '.')
money = money - 1
print('You now have ' + str(money) + 'dollars.')
print('--------------------------------------------------')
altluckyrollgame()
if lobby == 'back':
altvillagescene()
else:
print('Please type a valid option.')
print('--------------------------------')
altluckyrollgame()
*诸如altluckyrollgame()
或之类的功能altvillagescene()
是游戏逻辑的一部分并在其他地方定义,因此您可以忽略它们。