Question
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()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started