Question: when I run this code, it gives me an error. please don't change the code entirely. I just want to fix this error without altering
when I run this code, it gives me an error. please don't change the code entirely. I just want to fix this error without altering the entire structure as much as I can. please don't use breaks, passes, or global variables.
# Define constant variables for point values of different shots POINT_1_SHOTS = 1 POINT_2_SHOTS = 2 ADD_MATCH = 1 QUIT = 2
# Define the main function
def main():
name_match = "" shots_attempted = 0 percent_shots = 0.00 option = 0 total_points = 0 matches_count = 0
print_menu()
option = get_option(option)
if option == QUIT: print_goodbye(name_match, total_points, matches_count) else: while(option != QUIT): if option == ADD_MATCH: 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) #print_points() print_menu() option = get_option(option) else: print("Invalid option, please try again.") print_menu() option = get_option(option)
#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))
def print_match_name(name_match): print("Thanks for playing", name_match)
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
