Question: What can i replace while true with in this python code whichwill make it function the same ,but not have a while true loopbecause my

What can i replace while true with in this python code whichwill make it function the same ,but not have a while true loopbecause my professor says that while true and infinite loops arebad programming.

numbers = [] #list to store all the numbers
#prompt the user for first input
n = float(input('Please enter the first value: '))
numbers.append(n) #append it to list
#continue running a loop till the user does not enter 0
while True:
n = float(input('What is the next value? ')) #ask fora number
if n==0: #if its 0, break the loop
break
else:
numbers.append(n) #otherwise append it tolist

#print the results required
print('There are',len(numbers),'values') #len() method gives thecount of numbers
print('The minimum value is',min(numbers)) #min() method gives theminimum value
print('The maximum value is',max(numbers)) #max() method gives themaximum value
print('The average is',(sum(numbers)/len(numbers))) #compute theaverage

#for median calculation, if count of numbers is even, append a 0to the list
if(len(numbers)%2 == 0):
numbers.append(0)
#now compute median by sorting the list and finding out the middleelement
numbers.sort()
print('The median is',numbers[int(len(numbers)/2)])

The assignment is supposed to ask for a number input until theuser inputs 0. Then the program gives the minimum, maximum,median and average of all the numbers. Its does this already but Ineed to have the same results but without a while trueloop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!