我正在努力处理我的代码,似乎无法弄清楚。所以用户输入他们必须从多少钱开始。然后他们输入他们想要下注的金额。然后程序输出他们是赢、输、推还是得到二十一点。获得每个的概率显示在 if 语句的游戏函数中。我想要做的是将他们获得的总数作为新总数,然后用户继续从新总数下注,直到他们输入“x”以结束程序。我不知道该怎么做。
import random
print('BLACKJACK!')
print('')
print('Blackjack payout is 3:2')
print('Enter \'x\' for bet to exit')
print('')
money = float(input('Starting money: '))
#global variables
bet_amount = 0
#play the game
def game(bet_amount):
total = float(money)
number = random.randint(1, 100)
if number >= 6 and number <= 42:
print('You won.')
print('Money: ', total + int(bet_amount))
elif number >= 43 and number <= 51:
print('You pushed')
print('Money: ', total - int(bet_amount))
elif number >=52 and number <= 100:
print('You lost.')
print('Money: ', total)
elif number >= 1 and number <= 5:
print('You got a blackjack!')
print('Money: ', ((int(bet_amount) * 1.5) + total))
return total
def main():
while True:
print('')
bet_amount = input('Bet amount: ')
if bet_amount == 'x':
print('Bye!')
break
else:
game(bet_amount)
if __name__ == "__main__":
main()
相关分类