Python 如果键和值不唯一,则字典不更新

Python 如果键和值不唯一,则字典不更新,python,python-3.x,dictionary,Python,Python 3.x,Dictionary,我是python新手,我正在创建这个赌博游戏,用户可以选择在将要生成的符号上下注(最终-还没有到那里)。我正在创建一个字典来保存用户下注的金额(值)和他们下注的符号(键)对应的数字。每个玩家可以选择每回合下注1次以上。我遇到了一个问题,如果两个不同的玩家输入相同的赌注和符号组合(例如1:10美元(皇冠)),那么字典将不会更新为包含2个1:10的单独条目,它将只有一个1:10的条目。这就是我现在的工作 def getPlayers(): print("Hello and Welcome

我是python新手,我正在创建这个赌博游戏,用户可以选择在将要生成的符号上下注(最终-还没有到那里)。我正在创建一个字典来保存用户下注的金额(值)和他们下注的符号(键)对应的数字。每个玩家可以选择每回合下注1次以上。我遇到了一个问题,如果两个不同的玩家输入相同的赌注和符号组合(例如1:10美元(皇冠)),那么字典将不会更新为包含2个1:10的单独条目,它将只有一个1:10的条目。这就是我现在的工作

def getPlayers():

    print("Hello and Welcome to the Crown and Anchor Game")
    num = int(input('Please enter the number of people playing today: ')) # takes the number of people who are playing from the user
    scoreInit = [] # creating an empty list for the players inital score of 10

    for i in range(num): # for loop to append the inital score of 10 to the empty list scoerInit for the amount of players input 
        scoreInit += i * [10]

    return scoreInit # returns the list of inital scores for the amount of players playing


def collectBets(balance):
    bets = {}
    index = 0
    for i in balance:
        index += 1
        print('Player %d, what would you like to do this round?'  % (index))
        print('1: Bet on a symbol')
        print('2: Skip this round')
        userOpt = int(input('Please enter 1 or 2 depending on your choice: ')) # assigning what the user inputs as the variable 'usesrOpt'
        if userOpt == 1: # if user decides to bet:
            betTimes = int(input('How many times would you like to bet this round?: '))
            for a in range(betTimes):
                betAmount = int(input('Enter the amount you would like to bet this round: $1, $2, $5, or $10: '))
                symbol = int(input('Enter the number corresponding to the symbol you would like to bet on\n' # asking user what symbol they want to bet on - assigning it to a variable
                                       '1: Crown\n'
                                       '2: Anchor\n'
                                       '3: Heart\n'
                                       '4: Diamond\n'
                                       '5: Club\n'
                                       '6: Spade\n'
                                       ))                       

            bets.update({symbol:betAmount})


print(bets)

def main():
    balance1 = getPlayers()
    collectBets(balance1)

main()

任何帮助都将不胜感激!谢谢大家!

最好将Python字典视为“一组未排序的键:值对,要求键是唯一的(在一个字典中)。”

也就是说,每当用户A选择10,然后用户B选择10;用户A的选择实际上被用户B的选择覆盖了。一本字典只能存放10本作为一把钥匙。为了解决您的解决方案,您必须使用其他一些数据结构。字典中的键应该是唯一的

解决问题的方法是使用不同级别的词典。你可以有一个玩家名字的字典,里面有他们的价值和符号的字典。但是,您的玩家名称必须是唯一的,否则您将遇到相同的问题

请给出一个带有所需输出的表格。