你有正确的想法,你想使用一个列表,每个玩家都有一个元素。
您可以为每个玩家初始化一个包含 $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
要跟踪什么。