I've attached my below code below, but it is having issues with calculating the correct averages. Please help!
print("------------------------------------------")print("Welcome to the average price calculator!")print("------------------------------------------")print("Please enter the price of each item, one at a time.")print("Enter a negative number when there are no more prices to enter.")print()
cnt = 0avg=0.0while(True):n = float(input("Enter the price of an item: "))avg =avg+ ncnt=cnt+1if(n<>breakavg = avg/(cnt)print("The average price is $",format(avg, ".3f"));
Extracted text: Tests example (0.0/2.0) Expected average spendage: Your program printed: Welcome to the average price calculator! $60.419 Please enter the price of each item, one at a time. Enter a negative number when there are no more prices to enter. Enter the price of an item: Enter the price of an item: Enter the price of an item: Enter the price of an item: The average price is $ 45.065 Test Failed: False != True Tests with random numbers (0.0/2.0) Expected: $10 Your program printed: Welcome to the average price calculator! Please enter the price of each item, one at a time. Enter a negative number when there are no more prices to enter. Enter the price of an item: Enter the price of an item: Enter the price of an item: Enter the price of an item: Enter the price of an item: The average price Test Failed: False != TrueExtracted text: Write a program that repeatedly asks the user for the price of a product, until the user enters a negative number to indicate there are no more prices to enter (sentinel value). The program should then return the average price. A sample run of your program: Welcome to the average price calculator! Please enter the price of each item, one at a time. Enter a negative number when there are no more prices to enter. Enter the price of an item: 99.9 Enter the price of an item: 35 Enter the price of an item: 12.5 Enter the price of an item: 42 Enter the price of an item: 9.99 Enter the price of an item: -1 The average price is $39.878
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here