# We need this library to generate a random number
import random
# --- 1. The Setup (Mise en Place) ---
# The computer chooses a secret temperature between 300 and 400.
optimal_temperature = random.randint(300, 400)
number_of_attempts = 7
print("You've discovered a secret ingredient!")
print("Let's find the perfect temperature to bake the cake.")
print(f"You have {number_of_attempts} attempts. Good luck!")
print("------------------------------------------")
# --- 2. The Baking Loop ---
# This loop will run for the number of attempts we have.
for attempt_number in range(1, number_of_attempts + 1):
# --- 3. Get the User's Guess ---
# We ask for input and convert it to an integer (a whole number).
guess = int(input(f"Attempt #{attempt_number}: Enter your guess (300-400): "))
# --- 4. The Logic (Check the Result) ---
if guess < optimal_temperature:
print(f"Your guess of {guess}°F is too cold! The cake is gooey and undercooked. Try a higher temperature.")
elif guess > optimal_temperature:
print(f"Your guess of {guess}°F is too hot! The cake is burnt to a crisp! Try a lower temperature.")
else:
# This code runs if the guess is exactly right.
print(f"Perfection! {guess}°F is the exact temperature. The cake is golden-brown and delicious.")
print("You've mastered the secret ingredient!")
break # Exit the loop immediately since we won.
# --- 5. The "Game Over" Condition ---
# This part of the code only runs if the loop finishes WITHOUT a 'break'.
# This means the player ran out of tries.
else:
print("\nOh no! You've run out of the secret ingredient.")
print(f"The correct temperature was {optimal_temperature} degrees. Better luck next time!")