Question
I just want to print the if-statement only when I enter 2. however, it also prints put the else statement, which I don't want. I
I just want to print the if-statement only when I enter 2. however, it also prints put the else statement, which I don't want. I just want to print the if-statement and keep it outside the while loop. please don't use global variables, passes or breaks. please don't alter the code. keep it as original as possible.
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) if option == QUIT: print(" Goodbye") 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) total_points += calc_total_points(POINT_1_SHOTS, POINT_2_SHOTS) matches_count += 1 print_match_name(name_match) 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))
def print_match_name(name_match): print("Thanks for playing", name_match)
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