Gamer Scores
A professional gamer needs a program that allows them to track their average score per round over the course of a game. Each game lasts five rounds and the possible score for each round is between 0 and 50.
Write a program that asks the user for their score for each of the five rounds. The score should be validated to ensure its between 0 and 50. Each valid score should then be added to a running total. After all five rounds have been entered, the total should be displayed to the user.
Enter score for round 1: 37 Enter score for round 2: 25 Enter score for round 3: 41 Enter score for round 4: 455 Invalid score, must be between 0 and 50. Enter score for round 4: 45 Enter score for round 5: 43 Total score: 191
total = 0
rounds = 5
FOR i FROM 1 TO rounds DO
SEND "Enter score for round " & i & ": " TO DISPLAY
RECEIVE score FROM KEYBOARD
WHILE score < 0 OR score > 50 DO
SEND "Invalid score, must be between 0 and 50." TO DISPLAY
SEND "Enter score for round " & i & ": " TO DISPLAY
RECEIVE score FROM KEYBOARD
END WHILE
total = total + score
END FOR
SEND "Total score: " & total TO DISPLAY
total = 0
rounds = 5
for i in range(rounds):
score = int(input("Enter score for round " + str(i + 1) + ": "))
while score < 0 or score > 50:
print("Invalid score, must be between 0 and 50.")
score = int(input("Enter score for round " + str(i + 1) + ": "))
total = total + score
print("Total score:", total)
total = 0 # Set total to 0
rounds = 5 # Set rounds to 5
# Repeat for the number of rounds
for i in range(rounds):
# Get the score from user
score = int(input("Enter score for round " + str(i + 1) + ": "))
# Validate score to be between 0 and 50
while score < 0 or score > 50:
# Display an error message
print("Invalid score, must be between 0 and 50.")
# Get the score from the user again
score = int(input("Enter score for round " + str(i + 1) + ": "))
# Increase the total by the validated score
total = total + score
# After repeating for rounds, display the total
print("Total score:", total)
Extension
Extend the program to create the average score per round for the user, and round it to 2 decimal places.
Enter score for round 1: 27 Enter score for round 2: 53 Invalid score, must be between 0 and 50. Enter score for round 2: 43 Enter score for round 3: 40 Enter score for round 4: 38 Enter score for round 5: 25 Total score: 173 The average score is 34.6