[Python] What areas of this code could be improved by experienced programmers? [closed]

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    Just Want advice from willing programmers on what they'd do differently or perhaps better in this code.

    There's nothing that needs fixing it works and solves the problem - reusable code for sharing game participants into different teams.

    import random

    # Lists to store team members
    team_1 = []
    team_2 = []

    # List of all available players
    available_players = [
    "Anastasia", "Eli", "Jamal", "Jada", "Theo", "Michelle", "Adam",
    "Rhea", "Charlie", "Jasmine", "Marley", "Kenji", "Sydney", "Yara"
    ]

    # Loop until both teams have 8 players
    while len(team_1) < 8 and len(team_2) < 8:

    # Team 1 selection
    if team_1:
    if len(team_1) < 8:
    pick = random.choice(available_players)
    team_1.append(pick)
    available_players.remove(pick)
    else:
    x = input("Hello Team 1\nChoose your captain: ")
    while x == "":
    x = input("Team 1 Captain Needed!: ")
    team_1.append(x)

    # Team 2 selection
    if team_2:
    if len(team_2) < 8:
    pick = random.choice(available_players)
    team_2.append(pick)
    available_players.remove(pick)
    else:
    x = input("Hello Team 2\nChoose your captain: ")
    while x == "":
    x = input("Team 2 Captain Needed!: ")
    team_2.append(x)

    # Game starts when both teams are full
    else:
    print("All Teams Full:")
    print("Team 1:", team_1)
    print("Team 2:", team_2)
    print("\nIt's Game Time!!")

    Continue reading...

Compartilhe esta Página