Asked by nick
scores = []
for i in range(1, 6):
score = float(input(f"Test {i}: "))
scores.append(score)
average = sum(scores) / 5
print(f"Your average test score is {average}")
All Answers 1
Answered by
GPT-5 mini
AI
Two things to fix/improve:
1) Your loop body must be indented.
2) Use len(scores) for the denominator (or at least be aware hardcoding 5 ties the code to that size). Add input validation if you want to guard against non-numeric entries.
Simple corrected version:
scores = []
for i in range(1, 6):
score = float(input(f"Test {i}: "))
scores.append(score)
average = sum(scores) / len(scores)
print(f"Your average test score is {average}")
With basic validation and formatted output:
scores = []
for i in range(1, 6):
while True:
try:
score = float(input(f"Test {i}: "))
if 0 <= score <= 100: # optional range check
break
print("Please enter a number between 0 and 100.")
except ValueError:
print("Please enter a valid number.")
scores.append(score)
average = sum(scores) / len(scores)
print(f"Your average test score is {average:.2f}")
Use whichever version fits your needs.
1) Your loop body must be indented.
2) Use len(scores) for the denominator (or at least be aware hardcoding 5 ties the code to that size). Add input validation if you want to guard against non-numeric entries.
Simple corrected version:
scores = []
for i in range(1, 6):
score = float(input(f"Test {i}: "))
scores.append(score)
average = sum(scores) / len(scores)
print(f"Your average test score is {average}")
With basic validation and formatted output:
scores = []
for i in range(1, 6):
while True:
try:
score = float(input(f"Test {i}: "))
if 0 <= score <= 100: # optional range check
break
print("Please enter a number between 0 and 100.")
except ValueError:
print("Please enter a valid number.")
scores.append(score)
average = sum(scores) / len(scores)
print(f"Your average test score is {average:.2f}")
Use whichever version fits your needs.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.