Python Forum
How to assign a "Score" variable to each element in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign a "Score" variable to each element in a list
#1
Hey all, I was tasked to create a game for homework but I still can't seem to figure out how to assign each individual player a "Score" variable that changes as the game progresses. E.g.

If user inputs that there are 3 players, later in which the 3 players' names are appended into a list, how would I assign each player a individual variable in which it contains their respective scores?

import random
count = 0
playerList = []
def rollTurn():
    dice1 = random.randint(1,6)
    dice2 = random.randint(1,6)
    print("Your first dice rolled a: {}".format(dice1))
    print("Your second dice rolled a: {}".format(dice2))
print("-------------------------MAIN MENU-------------------------")
print("1. Play a game \n2. See the Rules \n3. Exit")
print("-------------------------MAIN MENU-------------------------")
userAsk = int(input("Enter number of choice"))
if userAsk == 1:
    userNun=int(input("Number of players?\n> "))
    while len(playerList) != userNun:
        userNames=input("Please input name of player number {}/{}\n> ".format(len(playerList)+1, userNun))
        playerList.append(userNames)
    random.shuffle(playerList)
    print("Randomizing list..:",playerList)
    print("It's your turn:" , random.choice(playerList))
    rollTurn()
    while count < 900000: 
        rollAgain=input("Would you like to roll again?")
        if rollAgain == "Yes":
            count = count + 1
            rollTurn()
        elif rollAgain == "No": 
            print("You decided to skip")
            break
This is what I currently have that pertains to this specific task. So what should I add so that each player/element in playerList is given a variable that contains their respective scores? Also(Sorry for asking multiple questions), as this game is round based, as I'm randomizing the order in which the players play, how would I that after each player is done, it picks the player directly after the current player, in other words, how would I pick the element directly after? I know there's a function for that but I can't seem to remember... Thanks for entertaining my ignorance and any help would be much appreciated, thanks :)
Reply


Messages In This Thread
How to assign a "Score" variable to each element in a list - by Reta - May-15-2019, 09:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 2,479 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  How do you find the length of an element of a list? pav1983 13 4,910 Jun-13-2020, 12:06 AM
Last Post: pav1983
  Methods that return the highest score from the list erfanakbari1 7 7,175 Mar-26-2019, 08:32 PM
Last Post: aankrose
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,519 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Extracting list element with user input valve 1 2,587 Mar-11-2019, 07:37 PM
Last Post: Yoriz
  Average score MartinEvtimov 5 6,856 Apr-02-2017, 07:35 PM
Last Post: ichabod801
  maximum and minimum element from the list and return output in dict MeeranRizvi 1 3,747 Jan-02-2017, 02:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020