3.Football Cards Python Fundamentals
Здравейте! Може ли една корекция на кода? Judge ми дава 80/100
Most football fans love it for the goals and excitement. Well, this problem doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior.
The rules: Two teams, named "A" and "B" have 11 players each. The players on each team are numbered from 1 to 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, the game is stopped immediately by the referee, and the team with less than 7 players loses.
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' means player #7 from team B received a card.
The task: Given a list of cards (could be empty), return the number of remaining players on each team at the end of the game in the format: "Team A - {players_count}; Team B - {players_count}". If the game was terminated print an additional line: "Game was terminated"
Note for the random tests: If a player that has already been sent off receives another card - ignore it.
Input
The input (the cards) will come on a single line separated by a single space.
Output
Print the remaining players as described above and add another line (as shown above) if the game was terminated.
Example
Input |
Output |
A-1 A-5 A-10 B-2 |
Team A - 8; Team B - 10 |
A-1 A-5 A-10 B-2 A-10 A-7 A-3 |
Team A - 6; Team B - 10 Game was terminated |
list_cards = input().split() #The task: Given a list of cards (could be empty) !!? playersA = 11 playersB = 11 list_of_all_cards = [] for i in list_cards: if i not in list_of_all_cards: list_of_all_cards.append(i) for card_index in range(len(list_of_all_cards)): list_of_current_card = list_of_all_cards[card_index].split("-") if list_of_current_card[0] == "A": playersA -= 1 elif list_of_current_card[0] == 'B': playersB -= 1 print(f"Team A - {playersA}; Team B - {playersB}") if playersA < 7 or playersB < 7: print('Game was terminated')