make a function that makes a world cup draw for 4 people in python

To make a world cup draw for 4 people, we can write a Python function that randomly assigns each person to a team. Here's one way to do it:

main.py
import random

def world_cup_draw(players):
    teams = ['Brazil', 'Germany', 'Spain', 'Argentina']
    random.shuffle(teams)
    return dict(zip(players, teams))

# Example usage:
players = ['Alice', 'Bob', 'Charlie', 'Dave']
draw = world_cup_draw(players)
print(draw)
270 chars
12 lines

In this example, we define a function world_cup_draw that takes a list of player names as a parameter. The function creates a list of team names, shuffles it randomly, and then uses zip to combine the player names with the team names into a dictionary. The function returns this dictionary, which maps each player to a team.

To use this function, we simply call it with a list of player names, and it returns a dictionary that we can print out to see the results. In the example code above, we define a list of players ['Alice', 'Bob', 'Charlie', 'Dave'], and then call the world_cup_draw function with this list. The resulting dictionary is stored in the variable draw, and then printed out using print(draw).

gistlibby LogSnag