Advertisement
mirovlad

Name Game Fixed

May 17th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         winner = player
  31.  
  32. # At this point winner should contain the last player that has the top_score
  33. if winner is not None:
  34.     print(f"The winner is {winner['name']} with {winner['score']} points!")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement