Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I formulated the code block for a while loop program below, but I have been asked to use try / except instead. Could someone please

I formulated the code block for a while loop program below, but I have been asked to use try/ except instead. Could someone please help with this?
n =0 # variable to store user inputting integers
my_list =0 # variable to store the sum of integers
count =0 # variable to count the total number of integers input
# loop till n's input value is not -1
while n !=-1:
# input for the value of an integer
n = int(input("Enter a number (-1 to quit): "))
# If n is not -1, add n to my_list and increase the count by 1
if n !=-1:
my_list = my_list + n
count = count +1
# print my_list/count, which provides the average of all counted integers
print("The average of numbers is ", my_list/count)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions

Question

Your funding sources regulations (what the payers require) P987

Answered: 1 week ago