您如何创建具有有效投注功能的游戏?

How do you create a game with a working betting feature?

我是 Python 的新手,一般来说是编码方面的新手。我想知道有人可以看看我需要更改什么...

    # Amount of chips player has

    starting_chips = 1000

    print('Player 1 has {}\n'.format(starting_chips))

    # Amount of chips player wants to bet
    try:
        placed_bet = int(input('Place your bet: '))
    except ValueError:
        print("Sorry, I didn't understand that.")
        continue
    print('')

    if placed_bet > starting_chips:
        print("You don't have enough funds")
        continue
    else:
        break

# A deduction from players total chips of the total bet
total_chips = (starting_chips - placed_bet)

losing_total = (starting_chips - placed_bet)

print('You now have: {}\n'.format(total_chips))

#If the player wins the hand
total_chips = ((placed_bet * 2) + starting_chips)

link 到这里的整个代码 --> https://github.com/Joeet33/CardGame

而不是 starting_chips 为什么不使用 total_chips 并在 while 循环之前初始化它?最终您要修改的变量是 "how many chips does the player have"。 starting_chips 可以用作脚本顶部提供的常量 STARTING_CHIPS = 1000,然后 total_chips = STARTING_CHIPS 位于 while 循环的正上方。

最终,每次 while 循环 returns 到顶部时,它都会将所有值重置回原来的 1000。