# Roll until you win
# while + random — the loop that stops when luck decides

import random

# ─────────────────────────────────────────────
# Roll until you hit 6
# ─────────────────────────────────────────────

roll = 0
attempts = 0

while roll != 6:
    roll = random.randint(1, 6)
    attempts += 1
    print(f"Rolled: {roll}")

print(f"Got 6 after {attempts} attempt(s).")

# Rolled: 3
# Rolled: 1
# Rolled: 5
# Rolled: 6
# Got 6 after 4 attempt(s).
# — different every run

# ─────────────────────────────────────────────
# while True + random
# ─────────────────────────────────────────────

print("Searching for the lucky number...")

while True:
    number = random.randint(1, 100)
    if number == 42:
        print(f"Found it: {number}")
        break
    print(f"Not yet: {number}")

# could be 3 iterations — could be 300
# you genuinely don't know

# ─────────────────────────────────────────────
# Guessing game
# ─────────────────────────────────────────────

secret = random.randint(1, 10)
guess = 0
attempts = 0

while guess != secret:
    guess = int(input("Guess a number (1-10): "))
    attempts += 1
    if guess < secret:
        print("Too low.")
    elif guess > secret:
        print("Too high.")

print(f"Correct! Got it in {attempts} attempt(s).")

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# generate random value inside the loop — fresh each iteration
# counter: define before, update inside, use after
# while True + break works when exit condition is inside the logic
# every run gives different results — test it multiple times
