Question

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 two parameters, a dictionary and a string, and will return the dictionary.

You program should have a menu as follows:

  • (1) Add Free Throw
  • (2) Add Two Pointer
  • (3) Add Three Pointer
  • (4) Display Statistics
  • (5) Exit

You should display the following when the user chooses statistics:

  • Each player and their respective score
  • Number of players
  • Total of all scores
  • Average score per player

You should create a rough-sketch of the flow of this program, before you start coding. Consider the following:

  • Display the menu
  • Prompt the user for the menu choice
  • If adding points throw
    • prompt the user for the player name and then call the appropriate function
  • else if displaying statistics
    • show the total, average, max, and min scores
  • else if exit the program
    • display exit message
  • else display error message

You should also create a rough-sketch of each function before you start coding. Consider the following for the free throw function:

  • Determine if the player is already in the dictionary (hint: consider the get() function)
  • If the player is in the dictionary
    • update their score. Get the current score, determine the new score, and update the dictionary
  • else
    • add the player and score to the dictionary

Your program should continue to prompt the user until menu choice 5 is entered. If the user enters an invalid menu choice, display Invalid menu choice

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

Code as text:

# this function will add 1 point to players total score

def freeThrowMade(playerDictionary, playerName):

if playerDictionary.get(playerName) == None:

playerDictionary[playerName] = 1

else:

playerDictionary[playerName] += 1

return playerDictionary

# this function will add 2 points to players total score

def twoPointMade(playerDictionary, playerName):

if playerDictionary.get(playerName) == None:

playerDictionary[playerName] = 2

else:

playerDictionary[playerName] += 2

return playerDictionary

# this function will add 3 points to players total score

def threePointMade(playerDictionary, playerName):

if playerDictionary.get(playerName) == None:

playerDictionary[playerName] = 3

else:

playerDictionary[playerName] += 3

return playerDictionary

# main driver

def main():

playerDictionary = dict() # define dictionary of players

# display menu

print("****Menu****")

print("1. Add Free Throw")

print("2. Add Two Pointer")

print("3. Add Three Pointer")

print("4. Display Statistics")

print("5. Exit")

# ask user choice until want to exit

while True:

choice = int(input("Enter your choice: "))

if choice == 1: #add 1 point

playerName = input("Enter player name: ")

freeThrowMade(playerDictionary, playerName)

elif choice == 2: #add 2 points

playerName = input("Enter player name: ")

twoPointMade(playerDictionary, playerName)

elif choice == 3: #add 3 points

playerName = input("Enter player name: ")

threePointMade(playerDictionary, playerName)

elif choice == 4: #display statistics

playerCount = 0

totalScore = 0

print("\n****Displaying Statistics****\n")

# print each player name and score

for name in playerDictionary:

print("%10s %3d" %(name, playerDictionary[name]))

playerCount += 1

totalScore += playerDictionary[name]

print("Number of players: ", playerCount)

print("Total of all scores: ", totalScore)

print("Average score per player: %.2f" % (totalScore/playerCount))

elif choice == 5: # exit

print("Exiting!!")

break

else: # invalid choice

print("Invalid menu choice.")


main()

Sample Run:

P.s.: Ask any doubts in comments and don't forget to rate the answer

Add a comment
Know the answer?
Add Answer to:
In this project, you will use functions and dictionaries to track basketball players and their respective...
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
  • Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

    Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an...

    Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an interactive program that performs fractional calculations. You need define a class CFrac for a fractional number according to the UML diagram below: CFrac - numerator : int - denominator : int - simplify () : void + CFrac (int = 0, int = 1) + ~CFrac() + add (const CFrac&) const : CFrac + subtract (const CFrac&) const : CFrac + multiply (const CFrac&)...

  • java Part 1 Create a NetBeans project that asks for a file name. The file should...

    java Part 1 Create a NetBeans project that asks for a file name. The file should contain an unknown quantity of double numeric values with each number on its own line. There should be no empty lines. Open the file and read the numbers. Print the sum, average, and the count of the numbers. Be sure to label the outputs very clearly. Read the file values as Strings and use Double.parseDouble() to convert them. Part 2 Create a NetBeans project...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • c++ A menu-driven program gives the user the option to find statistics about different baseball players....

    c++ A menu-driven program gives the user the option to find statistics about different baseball players. The program reads from a file and stores the data for ten baseball players, including player’s team, name of player, number of homeruns, batting average, and runs batted in. (You can make up your data, or get it online, for example: http://espn.go.com/mlb/statistics ) Write a program that declares a struct to store the data for a player. Declare an array of 10 components to...

  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

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