-2

这就是我到目前为止所拥有的。我想为每个玩家更新银行,但我不知道如何将每个玩家连接到他们的银行?

我希望它看起来像这样:

How many players are in the game: 4
Player 1 you have $1000
What is your bet: 65
Player 2 you have $1000
What is your bet: 7
Player 3 you have $1000
What is your bet: 88
Player 4 you have $1000
What is your bet: 8

虽然在一边,代码计算了每个玩家现在在一边有多少,我不希望它被打印出来,只是保存在内存中以备后用。我想我做错了。

4

1 回答 1

1

你有正确的想法,你想使用一个列表,每个玩家都有一个元素。

您可以为每个玩家初始化一个包含 $1000 的列表:

bank = [1000] * players

现在,您可以分别更新每个银行:

bank[i] = bank[i] - bet
print bank[i]

所以你会有类似的东西:

"""
Player limit of up to 7 players. Has to be more than one player.
"""
players = int(raw_input("How many players are in the game: "))
while players == "" or players == 0 or players == 1 or players > 7:
    players = int(raw_input("How many players are in the game: "))
bank = [1000] * players
for i in range (players):
    print "Player " + str(i+1) + " you have " + "$" + str(bank)
    bet = int(raw_input("What is your bet: "))
    while bet <= 0 or bet > 1000:
        bet = int(raw_input("What is your bet: "))

    bank[i] = bank[i] - bet
    print bank[i]

我不完全确定bankinventory要跟踪什么。

于 2012-07-31T18:55:01.777 回答