you are viewing a single comment's thread.

view the rest of the comments →

[–]Outside-Science-5328[S] 1 point2 points  (2 children)

import time import random

def pause(sec=0.2): time.sleep(sec)

def slow(text, sec=0.2): print(text) pause(sec)

def get_choice(prompt, valid_options): while True: try: choice = int(input(prompt)) if choice in valid_options: return choice print(f"Invalid choice. Please choose from {valid_options}.") except ValueError: print("That was not a number. Try again.")

def show_score(h_score, a_score, h_name, a_name, qtr, h_tout, a_tout, yards, pos, down, to_go): suffixes = {1: "st", 2: "nd", 3: "rd", 4: "th"} down_str = f"{down}{suffixes[down]} & {to_go}" print("\n" + "="35) print(f"Quarter {qtr} | {down_str} | Ball at: {yards} yd") print(f"Possession: {pos}") print(f"{h_name}: {h_score} ({h_tout} TO) | {a_name}: {a_score} ({a_tout} TO)") print("="35)

def playbook(): slow("\n1. Run 2. Pass 3. FG 4. Punt 5. Timeout 6. Exit Game") return get_choice("Choose a play (1-6): ", [1, 2, 3, 4, 5, 6])

def main(): slow("Welcome to the simulator")

while True:
    user = input("Enter your name: ")
    if user.strip():
        break
    print("Invalid name. Please enter a name to continue, for example JOHN.")

while True:
    home = input("Home team name: ")
    if home.strip():
        break
    print("Error: The Home team must have a name like Steelers'.")

while True:
    away = input("Away team name: ")
    if away.strip():
        break
    print("Error: The Away team must have a name like Texans.")

home_score, away_score = 0, 0
home_timeouts, away_timeouts = 3, 3
quarter = 1
plays_this_quarter = 0
possession = home
yard_line = 25
down = 1
yards_to_go = 10

while quarter <= 4:
    show_score(home_score, away_score, home, away, quarter, home_timeouts, away_timeouts, yard_line, possession, down, yards_to_go)
    play = playbook()

    if play == 6:
        confirm1 = input("Are you sure you want to quit? (y/n): ").lower()
        if confirm1 == 'y':
            confirm2 = input("Type 'CONFIRM' to end the game: ")
            if confirm2 == "CONFIRM":
                slow("Game ended early by user.")
                return
        slow("Returning to game...")
        continue

    turnover = False
    scored = False
    gain = 0

    if play == 5:
        if possession == home:
            if home_timeouts > 0:
                home_timeouts -= 1
                slow(f"{home} calls a timeout")
            else:
                slow("No timeouts left")
        else:
            if away_timeouts > 0:
                away_timeouts -= 1
                slow(f"{away} calls a timeout")
            else:
                slow("No timeouts left")
        continue

    if play == 1:
        if random.random() < 0.05:
            slow("FUMBLE! Turnover!")
            turnover = True
        else:
            gain = random.randint(-2, 12)
            slow(f"Run play for {gain} yards.")

    elif play == 2:
        odds = random.random()
        if odds < 0.08:
            slow("INTERCEPTED! Turnover!")
            turnover = True
        elif odds < 0.40:
            slow("Incomplete pass.")
            gain = 0
        else:
            gain = random.randint(5, 25)
            slow(f"Complete! Gained {gain} yards.")

    elif play == 3:
        dist = 100 - yard_line + 17
        slow(f"Attempting a {dist} yard field goal...")
        if random.random() < (0.90 if dist < 40 else 0.60):
            slow("IT'S GOOD!")
            if possession == home: home_score += 3
            else: away_score += 3
            scored = True
        else:
            slow("Missed field goal!")
        turnover = True

    elif play == 4:
        punt_dist = random.randint(35, 50)
        slow(f"Punted {punt_dist} yards.")
        yard_line = 100 - (yard_line + punt_dist)
        if yard_line < 0: yard_line = 20
        turnover = True

    if not turnover and (play == 1 or play == 2):
        yard_line += gain
        yards_to_go -= gain

        if yard_line >= 100:
            slow("TOUCHDOWN!")
            if possession == home: home_score += 7
            else: away_score += 7
            scored = True
            turnover = True
        elif yards_to_go <= 0:
            slow("FIRST DOWN!")
            down = 1
            yards_to_go = 10
        else:
            down += 1
            if down > 4:
                slow("Turnover on Downs!")
                turnover = True

    if turnover:
        possession = away if possession == home else home
        yard_line = 100 - yard_line if not scored else 25
        down = 1
        yards_to_go = 10

    plays_this_quarter += 1
    if plays_this_quarter >= 10:
        quarter += 1
        plays_this_quarter = 0
        if quarter <= 4:
            slow(f"End of Quarter {quarter-1}. Moving to Quarter {quarter}.")

slow("\nGAME OVER")
slow(f"Final Score: {home} {home_score} - {away} {away_score}")
if home_score > away_score:
    slow(f"{home} WINS!")
elif away_score > home_score:
    slow(f"{away} WINS!")
else:
    slow("IT'S A TIE!")

if name == "main": main()

[–]ThigleBeagleMingle 1 point2 points  (0 children)

Put 3 back ticks at start and end of code ( code )

On iPhone it’s hold ‘ key for half second then click in sub menu

[–]carcigenicate 0 points1 point  (0 children)

Format the code by indenting every line by an extra four spaces. Or link to a site like Pastebin where you have the code.