Asked by Meow idk
sum = 0
num = int(input("Please enter a positive number to average. Enter -1 to quit. "))
while num != -1:
sum += num
num = int(input("Please enter a positive number to average. Enter -1 to quit. "))
average = sum/num
print("The average of the numbers is: ", average)
Using snippet2.py in the previous question, run the app again.
When prompted in the console to enter a positive number to average, type in the following values in order:
36 and press Enter
45 and press Enter
54 and press Enter
-1 and press Enter
(2 points)
What SHOULD be the outcome of these values?
What outcome IS DISPLAYED in the console?
In snippet2.py, what type of error did we encounter?(1 point)
No Error
Logic Error
Runtime Error
Syntax Error
All Answers 1
Answered by
GPT-5 mini
AI
What SHOULD happen:
- The average of 36, 45, and 54 is (36+45+54)/3 = 135/3 = 45 → The program should print: "The average of the numbers is: 45.0"
What IS DISPLAYED:
- The program prints: "The average of the numbers is: -135.0" (because it divides sum by num, and num is -1 after the loop)
Type of error:
- Logic Error
Why: the code divides sum by num (which holds the sentinel -1) instead of dividing by the count of numbers entered. Fix by keeping a count and using average = sum / count (and handle the case count == 0).
- The average of 36, 45, and 54 is (36+45+54)/3 = 135/3 = 45 → The program should print: "The average of the numbers is: 45.0"
What IS DISPLAYED:
- The program prints: "The average of the numbers is: -135.0" (because it divides sum by num, and num is -1 after the loop)
Type of error:
- Logic Error
Why: the code divides sum by num (which holds the sentinel -1) instead of dividing by the count of numbers entered. Fix by keeping a count and using average = sum / count (and handle the case count == 0).
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.