Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
import random

def serve():
    if random.random() < 0.5:
        return True  # Team 1 serves
    else:
        return False  # Team 2 serves

def play_game():
    team1_score = 0
    team2_score = 0
    serving_team = serve()

    while True:
        if serving_team:
            print("Team 1 serves.")
        else:
            print("Team 2 serves.")

        # Simulate a rally
        rally_winner = random.choice([serving_team, not serving_team])
        
        if rally_winner:
            team1_score += 1
            print("Team 1 wins the rally!")
        else:
            team2_score += 1
            print("Team 2 wins the rally!")

        print(f"Score: Team 1 - {team1_score}, Team 2 - {team2_score}")
        
        # Check if a team has reached the winning score of 25 and has a lead of at least 2 points
        if team1_score >= 25 and team1_score - team2_score >= 2:
            print("Team 1 wins the game!")
            break
        elif team2_score >= 25 and team2_score - team1_score >= 2:
            print("Team 2 wins the game!")
            break
        
        # Switch serving team
        serving_team = not serving_team

play_game()