import random import time def slow_print(text): for char in text: print(char, end='', flush=True) time.sleep(0.02) print() def get_hit(): # Random outcome probabilities outcomes = ["strike", "strike", "strike", "out", "out", "single", "double", "triple", "home_run"] return random.choice(outcomes) def play_half_inning(team_name): outs = 0 runs = 0 bases = [0, 0, 0] # first, second, third slow_print(f"\n{team_name} is batting!") while outs < 3: input("Press Enter to swing...") result = get_hit() slow_print(f"Result: {result.upper()}") if result == "strike": slow_print("Strike!") continue elif result == "out": outs += 1 slow_print(f"Out! ({outs}/3 outs)") elif result == "single": runs += bases[2] bases = [1, bases[0], bases[1]] slow_print("Single!") elif result == "double": runs += bases[2] + bases[1] bases = [0, 1, bases[0]] slow_print("Double!") elif result == "triple": runs += sum(bases) bases = [0, 0, 1] slow_print("Triple!") elif result == "home_run": runs += sum(bases) + 1 bases = [0, 0, 0] slow_print("HOME RUN!!!") slow_print(f"Current runs this inning: {runs}") slow_print(f"{team_name} scored {runs} runs this inning.") return runs def play_game(): slow_print("Welcome to Simple Baseball Game!\n") team1 = input("Enter Team 1 name: ") team2 = input("Enter Team 2 name: ") innings = 3 # keep it short score1 = 0 score2 = 0 for inning in range(1, innings + 1): slow_print(f"\n=== Inning {inning} ===") score1 += play_half_inning(team1) score2 += play_half_inning(team2) slow_print(f"\nScore after inning {inning}:") slow_print(f"{team1}: {score1}") slow_print(f"{team2}: {score2}") slow_print("\n=== Final Score ===") slow_print(f"{team1}: {score1}") slow_print(f"{team2}: {score2}") if score1 > score2: slow_print(f"{team1} wins!") elif score2 > score1: slow_print(f"{team2} wins!") else: slow_print("It's a tie!") if __name__ == "__main__": play_game()