Question

In PYTHON: Ask how many players there are For each player Ask the player's name Roll...

In PYTHON:

  1. Ask how many players there are
  2. For each player
    1. Ask the player's name
    2. Roll a die for the player and store their score
    3. Use a dictionary with the name as key and die roll as value
  3. Print out the player's name who has the highest score
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation::

  • Code in PYTHON is given below
  • Please read comments for better understanding of the code
  • Screenshots of the Code is also provided
  • Screenshots of the OUTPUT are given at the end of the code


Code in PYTHON::

import random
'''
    Prompting user to enter the number of 
    players in variable named players
'''
players = int(input("Enter how many players:"))
'''
    A dictionary named dictPlayer is declared below
'''
dictPlayer={}
'''
    A variable named maximum is declared and initialized as
    1, it will be used to store the maximum value generated 
    so far randomly in range 1 to 6
'''
maximum=1

'''
    Following for loop runs for players number of times
    In each iteration we ask user to enter name in name variable
    Then we generate random number in die variable in range 1 to 6
    We add name as key and die as value in dictionary
    And we check if current die value is greater then or equal to maximum
    If yes then we update the maximum to die 
'''
for i in range(players):
    name = input("Enter player name:")
    die = random.randint(1,7)
    dictPlayer[name]=die
    if die>=maximum:
        maximum=die

'''
    In following for loop we iterate through dictionary 
    and check if current players value match to maximum
    If yes then we print the players name
'''
print("Players with maximum score",maximum,"is :")
for i in dictPlayer:
    if dictPlayer[i] == maximum:
        print(i)

Screenshot of the CODE:

OUTPUT::
TEST CASE 1:

TEST CASE 2:


Please provide the feedback!!

Thank You!!

Add a comment
Know the answer?
Add Answer to:
In PYTHON: Ask how many players there are For each player Ask the player's name Roll...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON: A college gives full scholarship to every player in its football team and men's...

    IN PYTHON: A college gives full scholarship to every player in its football team and men's basketball team. The coach of each team gives the name of every player to the athletic director. The athletic director needs a program to handle the names. He wants the program to tell him how many scholarships they need to give out this year. What data structure in Python is the best choice to store player names? [Note: a student who plays both sports...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • Create a Dice Game: PYTHON This game is between two people. They will roll a pair...

    Create a Dice Game: PYTHON This game is between two people. They will roll a pair of dice each 10 times. Each roll will be added to a total, and after 10 rolls the player with the highest total will be the Winner! You will use the RANDOM class RANDRANGE to create a random number from 1 to 6. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice. You must...

  • Complete each problem separately and perform in python. 1. Create a script that will roll five...

    Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...

  • Players A and B each roll a fair 6-sided die. The player with the higher score...

    Players A and B each roll a fair 6-sided die. The player with the higher score wins ¤1 from the other player. If both players have equal scores, the game is a draw and no one wins anything. i. Let X denote the winnings of player A from one round of this game. State the probability mass function of X. Calculate the expectation E(X) and variance Var(X). ii. What is the conditional probability that player A rolls , given that...

  • In this project, you will use functions and dictionaries to track basketball players and their respective...

    In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...

  • Help needed related python ! Thanx :) #First let's ask the user for one of their...

    Help needed related python ! Thanx :) #First let's ask the user for one of their favorite book. # Now let's use concatenation to ask who wrote this book. # Create an empty dictionary to hold the favorite books and authors. # Use a for loop to prompt the user to enter 5 of their favorite books. # A general structure is given below. for book in favorite_book range(5): print (book) favorite_book = input("What is one of your favorite books?...

  • A game involving two players with two possible strategies is a prisoner's dilemma if each player...

    A game involving two players with two possible strategies is a prisoner's dilemma if each player has a dominant strategy and: Select one: a. neither player plays their dominant strategy. b. each player's payoff is higher when both play their dominated strategy than when both play their dominant strategy. c. each player's payoff is lower when both play their dominant strategy than when both play their dominated strategy. d. there is a Nash equilibrium that yields the highest payoff for...

  • Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player,...

    Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT