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...


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 = 0
avg=0.0
while(True):
n = float(input("Enter the price of an item: "))
avg =avg+ n
cnt=cnt+1
if(n<>
break
avg = avg/(cnt)
print("The average price is $",format(avg, ".3f"));



Tests example (0.0/2.0)<br>Expected average spendage:<br>Your program printed:<br>Welcome to the average price calculator!<br>$60.419<br>Please enter the price of each item, one at a time.<br>Enter a negative number when there are no more prices to enter.<br>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<br>Test Failed: False != True<br>Tests with random numbers (0.0/2.0)<br>Expected: $10<br>Your program printed:<br>Welcome to the average price calculator!<br>Please enter the price of each item, one at a time.<br>Enter a negative number when there are no more prices to enter.<br>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<br>Test Failed: False != True<br>

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 != True
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.<br>A sample run of your program:<br>Welcome to the average price calculator!<br>Please enter the price of each item, one at a time.<br>Enter a negative number when there are no more prices to enter.<br>Enter the price of an item: 99.9<br>Enter the price of an item: 35<br>Enter the price of an item: 12.5<br>Enter the price of an item: 42<br>Enter the price of an item: 9.99<br>Enter the price of an item: -1<br>The average price is $39.878<br>

Extracted 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

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here