Question: Python add an outside the loop to avoid the division by zero and tell the user that you can t compute an average without data.

Python
add an outside the loop to avoid the division by zero and tell the user that you cant compute an average without data.
def main():
total =0
count =0
moreItems = True
while moreItems:
price = float(input('Enter price of item (0 when done): '))
if price !=0:
count = count +1
total = total + price
print('Subtotal: $', total)
else:
moreItems = False
average = total / count
print('Total items:', count)
print('Total $', total)
print('Average price per item: $', average)
main()

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 Databases Questions!