Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this program, I want the program to add the total points calculated and print them out when the user enters 2. When the user

For this program, I want the program to add the total points calculated and print them out when the user enters 2. When the user enters 2, it should print out You scored 29 points for two games. Thats an average of 14.5 points per game. A variable that adds all the total points and prints it. Another one to keep track of all the matches. I dont want to use global variables. Please keep this program as original as possible. I just want to add the total points calculation for all total points and a count variable to keep track of all matches. If the user enters 2 at the beginning of the program, it should print a goodbye message.

POINT_1_SHOTS = 1

POINT_2_SHOTS = 2

ADD_MATCH = 1

QUIT = 2

def main():

total_points = 0

matches_count = 0

name_match = ""

shots_attempted = 0

percent_shots = 0.00

option = 0

print_menu()

option = get_option(option)

while(option != 2):

if option == 1:

print_welcome()

name_match = get_match_name()

shots_attempted = get_attempted_shots()

POINT_1_SHOTS = get_point_1_shots()

POINT_2_SHOTS = get_point_2_shots()

percent_shots = calc_percent_shots(shots_attempted)

print_percent_shots(percent_shots)

total_points += calc_total_points(POINT_1_SHOTS, POINT_2_SHOTS)

matches_count += 1

print_menu()

option = get_option(option)

else:

print_goodbye(name_match, total_points, matches_count)

#Functions

def print_menu():

"""

This function prints a menu to the user giving them list of options to choose

from

"""

print("1. Enter 1 to add match")

print("2. Enter 2 to quit")

def get_option(option):

""""

option is defined and passed here. option is input, returned, and stored in

get_option()

"""

option = 0

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

return option

def print_welcome():

"""

function that prints welcome message

"""

print("Welcome to by basketball game. ")

def get_match_name():

"""

this function will define name_match, ask for the name match, and return it

"""

name_match = ""

name_match = input("Enter name of match: ")

return name_match

def get_attempted_shots():

"""

this function will ask for the attempted shots and return it

"""

shots_attempted = 0

shots_attempted = int(input("Enter number of shots you want to attempt: "))

return shots_attempted

def get_point_1_shots():

"""

This function will ask for 1 point shots and return it in the same line

"""

POINT_1_SHOTS = 1

POINT_1_SHOTS = int(input("Enter number of 1 point shots made: "))

return POINT_1_SHOTS

def get_point_2_shots():

"""

This function will ask for 1 point shots and return it in the same line

"""

POINT_2_SHOTS = 2

POINT_2_SHOTS = int(input("Enter number of 2 point shots made: "))

return POINT_2_SHOTS

def calc_percent_shots(shots_attempted):

"""

function below passes three arguments, percent_shots is defined to store

calculation, then clculated value will be returned

"""

percent_shots = 0.00

percent_shots = (POINT_1_SHOTS + POINT_2_SHOTS)/shots_attempted

return percent_shots

def print_percent_shots(percent_shots):

"""

This function will print the calculated value. Calculated value in function

above, mutiply that value by 100 and format it.

"""

print(" ","You made ", "{:.2f}".format (percent_shots * 100), " % of Attempted shots", sep="")

def calc_total_points(POINT_1_SHOTS, POINT_2_SHOTS):

"""

this function will calculate all of the total points

"""

total_points = POINT_1_SHOTS * 1 + POINT_2_SHOTS * 2

print("You scored {} points ".format(total_points))

return total_points

def print_goodbye(name_match, total_points, matches_count):

"""

Function below will print a goodbye message while passing the name_match as an

argument so the console can print it. In the goodbye message, it will also

print out the total points and divide by total_matches

"""

print(" Thanks for playing {}!".format(name_match))

print(" You scored a total of {} points in {} matches.".format(total_points, matches_count))

print("That's an average of {:.1f} points per game.".format(total_points/matches_count))

main()

image text in transcribed
image text in transcribed
1. Enter 1 to add match 2. Enter 2 to quit Enter your option: 1 Welcome to by basketball game. Enter name of match: and Enter number of shots you want to attempt: 30 Enter number of 1 point shots made: 1 Enter number of 2 potnt shots made: 6 You made 10.00% of Attempted shots You scored 13 points 1. Enter 1 to add match 2. Enter 2 to quit Enter your option: 1 Welcome to by basketball game. Enter name of match: same Enter number of shots you want to attempt: 2 Enter number of 1 point shots made: 1 Enter number of 2 point shots made: 4 You made 150.00 \% of Attempted shots You scored 9 points 1. Enter 1 to add match 2. Enter 2 to quit Enter your option: 2 Thanks for playing same! You scored a total of 22 points in 2 matches. That's an average of 11.0 points per game. 1. Enter 1 to add match 2. Enter 2 to quit Enter your option: 2 Thanks for playing ! You scored a total of 0 points in 0 matches. Traceback (most recent call last): File "main.py", line 205, in main() File "main.py", line 60, in main print_goodbye(name_match, total_points, matches_count) File "main.py", line 201, in print_goodbye print("That's an average of {:.1f} points per game." format(total_poi nts/matches_count)) ZeroDivisionError: division by zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Explain why evaluation is important.

Answered: 1 week ago

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago