Question
Modify this program to use exception handling you must use at least one try, accept, and final block for each function. #Function to get numbers
Modify this program to use exception handling you must use at least one try, accept, and final block for each function.
#Function to get numbers
def get_numbers():
#Declare list
numbers = []
#Prompt for input
count = int(input("How many numbers would you like to enter? "))
for i in range(count):
number = int(input("Enter a number: "))
numbers.append(number)
return numbers
#Function to get count
def get_count(numbers):
return len(numbers)
#Function to get sum
def get_sum(numbers):
total = 0
for number in numbers:
total += number
return total
#Function to get smallest
def get_smallest(numbers):
smallest = numbers[0]
for number in numbers:
if number < smallest:
smallest = number
#Return result
return smallest
def get_average(numbers):
return get_sum(numbers) / get_count(numbers)
numbers = get_numbers()
#Output results
print("Number of numbers entered:", get_count(numbers))
print("Sum of numbers:", get_sum(numbers))
print("Smallest number:", get_smallest(numbers))
print("Average of numbers:", get_average(numbers))
Fix any errors and make any changes from grading feedback.
Each function must have a try, accept, and finally block.
Your program should not crash on the wrong input.
If the wrong input is entered your program must do the following:
Tell the user their input is incorrect
Allow the user to enter another value
Reminder:
Program Header and method headers are required
All prints to the console must be described.
This program should not crash on any input given.
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