~2 min read • Updated Oct 13, 2025
Program Overview
This Python program reads match results line by line, where each line contains the winning team’s name and the points earned.
If the input is -, the program ends and displays the total score for each team.
Up to 100 teams are supported.
Python Code:
def record_scores():
scores = {}
print("Enter match results (type '-' to finish):")
while True:
line = input("Team name and score: ").strip()
if line == "-":
break
try:
team, point = line.split()
point = int(point)
scores[team] = scores.get(team, 0) + point
except ValueError:
print("Invalid input. Please enter team name and score separated by space.")
return scores
def display_results(scores):
print("\nFinal Score Report:")
for team, total in sorted(scores.items(), key=lambda x: -x[1]):
print(f"{team}: {total} points")
# Run the program
scores = record_scores()
display_results(scores)
Sample Output:
Team name and score: Lions 3
Team name and score: Tigers 2
Team name and score: Lions 4
Team name and score: -
Final Score Report:
Lions: 7 points
Tigers: 2 points
Written & researched by Dr. Shahin Siami