Question: Chapter 5: Test and debug the program Specifications Create a list of valid entries and the correct results for each set of entries. Then, make
Chapter 5: Test and debug the program Specifications Create a list of valid entries and the correct results for each set of entries. Then, make sure that the results are correct when you test with these entries. Create a list of invalid entries. These should include entries that test the limits of the allowable values. Then, handle the invalid integers (such as negative integers and unreasonably large integers). In addition, make sure the user cant enter data that doesnt make sense (such as a player having more hits than at bats). Dont attempt to handle invalid entries that cause exceptions, such as the user entering a string like x for an integer value. You can do that after you read chapter 8.
code that need to be updated
def menu_options(): #Main Menu print("MENU OPTIONS") print("1 Calculate batting average") print("2 - Exit program") return # def calculate_batting_average(number_hits, at_bats): #Calc Batting Average batting_average = round((number_hits / at_bats), 3) return batting_average # ###### Main Function ###################################### # def main(): # display a welcome message print("================================================================") print("Baseball Team Manager") print() menu_options() print("================================================================") print() # Baseball team manager menu # while True: menu_option = int(input("Menu option: " ))
while menu_option != 1 and menu_option !=2: print("Not a valid option. Please try again") print() menu_options() menu_option = int(input("Menu option: " ))
if menu_option == 1: print() print("Calculating batting average...")
# Get input from the user at_bats = int(input("Official number of at bats: ")) number_hits = int(input("Number of hits:\t")) # Calculate batting average batting_average = calculate_batting_average(number_hits, at_bats) # Format and display the result print("Batting average:", str(batting_average)) print() if menu_option == 2: print("Bye!") break
if __name__ == "__main__": main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
