Skip to content
Sign upLog in
← Back to Community

Python : Code

Profile icon

olympic_boxers = ['Mary Kom','Nicola Adams','Claressa Sheilds',
'Marlen Esparza','Natasha Jonas','Ren Cancan',
'Savannah Marshall','Mary Spencer']

Create a Round of 4 Random Matches between the Boxers. An example has been provided below.
Points to Note:
The boxer names should not be repeated.
All 8 boxers should have a Match.

Output Example:

Summer Olympics - Boxing

Mary Kom vs Ren Cancan
Nicola Adams vs Claressa Sheilds
Natasha Jonas vs Marlen Esparza
Mary Spencer vs Savannah Marshall

Profile icon
Profile icon
Profile icon

To avoid doubles you can remove the names from the list.
First get them in a random order, then pop (get and remove) the names.

random.shuffle(names) b1 = names.pop(0) # get & remove first name b2 = names.pop(0) print(f"{b1} vs {b2}") print(names)

Output if the names were not shuffled:

boxer1 vs boxer2 ["boxer3", "boxer4", "boxer5", "boxer6", "boxer7", "boxer8"]
Profile icon

I moved your post to the Share board, which is for sharing code.

Profile icon

Dont understand it bro