Guessing Game

PHOTO EMBED

Mon Sep 16 2024 18:35:27 GMT+0000 (Coordinated Universal Time)

Saved by @jerseyitguy #python

import random

def guess_the_number():
    number_to_guess = random.randint(1, 100)
    attempts = 0
    while True:
        guess = int(input("Guess the number (1-100): "))
        attempts += 1
        if guess < number_to_guess:
            print("Too low!")
        elif guess > number_to_guess:
            print("Too high!")
        else:
            print(f"Congratulations! You guessed the number in {attempts} attempts.")
            break

guess_the_number()
content_copyCOPY