Modify your program to use at least one method to perform the same task. You will also need to add exception handling to your program and to your method. MY CODE IS BELOW create a method to find the largest number Your method must perform the following The method must take in at least one value as a parameter. The method must return a value You must use Exception handling in your method
PYTHON ONLY PLZZZ
Modify your program to use at least one method to perform the same task. You will also need to add exception handling to your program and to your method.
MY CODE IS BELOW
- create a method to find the largest number
Your method must perform the following
- The method must take in at least one value as a parameter.
- The method must return a value
- You must use Exception handling in your method
HERE is my code
numList = []
while(True):
variable = input("Enter a number or Enter done to quit: ")
if(variable=='done'):
break
numList.append(int(variable))
# display the information
print("The total amount of numbers entered : ",len(numList))
print("The total of numbers : ",sum(numList))
print("The average of all numbers : ",sum(numList)/len(numList))
print("The largest number is: ",max(numList))
Modified Code with Exception Handling and methods:
def createList():
numList = []
while(True):
variable = input("Enter a number or Enter done to quit: ")
if(variable=='done'):
break
numList.append(int(variable))
if len(numList) > 0:
return numList
else:
print("List is empty!")
return 0
# display the information
list = createList()
if list != 0:
print("The total amount of numbers entered : ",len(list))
print("The total of numbers : ",sum(list))
print("The average of all numbers : ",sum(list)/len(list))
print("The largest number is: ",max(list))
else:
print("Cannot find largest number in an empty array.")
Step by step
Solved in 2 steps with 2 images