mirovlad

Name Game

May 13th, 2022 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # https://judge.softuni.org/Contests/Practice/Index/1745
  2.  
  3. players = []
  4. top_score = None  # We'll determine the top score during input
  5. user_input = input()
  6. while user_input != "Stop":
  7.     player = {
  8.         "name": user_input,
  9.         "score": 0,
  10.     }
  11.  
  12.     for char in player["name"]:
  13.         number = int(input())  # Player enters number for each character in their name
  14.         if number == ord(char):  # If number matches asc
  15.             player["score"] += 10
  16.         else:
  17.             player["score"] += 2
  18.  
  19.     if top_score is None or top_score < player["score"]:
  20.         top_score = player["score"]
  21.  
  22.     players.append(player)
  23.     user_input = input()
  24.  
  25. # Find the winner
  26. winner = None
  27. for player in players:
  28.     if player["score"] == top_score:  # We are only interested in people who have the top score
  29.         # The player has the top score
  30.         if winner is None:
  31.             winner = player  # 1st top player automatically becomes winner
  32.         else:
  33.             winner = player  # 2nd top player replaces the first one
  34.             break  # Leave loop right away, so any further top players are ignored
  35.  
  36. if winner is not None:
  37.     print(f"The winner is {winner['name']} with {winner['score']} points!")
  38.  
Add Comment
Please, Sign In to add comment