Created
January 13, 2023 09:31
-
-
Save mrkatey/ef0eec62da45013d03a7bae5b96c9ec4 to your computer and use it in GitHub Desktop.
ping_pong_tournament
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tournament(players=None, total_matches=25): | |
...: import datetime | |
...: from random import shuffle | |
...: assert players is not None, 'Must add list of 2 or more players!' | |
...: matches = [] | |
...: while len(matches) < total_matches: | |
...: shuffle(players) | |
...: for p in players: | |
...: for p2 in players: | |
...: if p != p2: | |
...: print(f"Match! {p} vs {p2}") | |
...: score_1 = input(f"What was {p}'s score?") | |
...: score_2 = input(f"What was {p2}'s score?") | |
...: matches.append([{'player_1':{'name':p, 'score':score_1}},\ | |
...: {'player_2':{'name':p2, 'score':score_2}}, datetime.datetime.now()]) | |
...: return matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment