SimeonTs

SUPyF2 Lists Basics Exercise - 03. Football Cards

Oct 3rd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. """
  2. Lists Basics - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1725#2
  4.  
  5. SUPyF2 Lists Basics Exercise - 03. Football Cards
  6.  
  7. Problem:
  8. Most football fans love it for the goals and excitement. Well, this problem doesn't.
  9. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior.
  10. The rules: Two teams, named "A" and "B" have 11 players each. The players on each team are numbered from 1 to 11.
  11. Any player may be sent off the field by being given a red card. If one of the teams has less than 7 players remaining,
  12. the game is stopped immediately by the referee, and the team with less than 7 players loses.
  13.  
  14. A card is a string with the team's letter ('A' or 'B') followed by a single dash and player's number. e.g the card 'B-7'
  15. means player #7 from team B received a card. (index 6 of the list)
  16. The task: Given a list of cards (could be empty),
  17. return the number of remaining players on each team at the end of the game in the format:
  18. "Team A - {players_count}; Team B - {players_count}".
  19. If the game was terminated print an additional line: "Game was terminated"
  20. Note for the random tests: If a player that has already been sent off receives another card - ignore it.
  21. Input
  22. The input (the cards) will come on a single line separated by a single space
  23. Output
  24. Print the remaining players as described above and add another line (as shown above) if the game was terminated
  25.  
  26. Example
  27. Input:                          Output:
  28. A-1 A-5 A-10 B-2                Team A - 7; Team B - 9
  29. -------------------------------------------------------
  30. A-1 A-5 A-10 B-2 A-10 A-7       Team A - 6; Team B - 9
  31.                                Game was terminated
  32. """
  33. team_A = ["A-1", "A-2", "A-3", "A-4", "A-5", "A-6", "A-7", "A-8", "A-9", "A-10", "A-11"]
  34. team_B = ["B-1", "B-2", "B-3", "B-4", "B-5", "B-6", "B-7", "B-8", "B-9", "B-10", "B-11"]
  35. game_terminated = False
  36.  
  37. red_cards = [player for player in input().split(" ")]
  38. for player in red_cards:
  39.     if "A" in player and player in team_A:
  40.         team_A.remove(player)
  41.     if "B" in player and player in team_B:
  42.         team_B.remove(player)
  43.     if len(team_A) < 7 or len(team_B) < 7:
  44.         game_terminated = True
  45.  
  46. print(f"Team A - {len(team_A)}; Team B - {len(team_B)}")
  47. if game_terminated:
  48.     print("Game was terminated")
Add Comment
Please, Sign In to add comment