Back to articles
Guess The Number Higher or Lower

Guess The Number Higher or Lower

via Dev.to PythonDharani

Introduction The "Guess the Number (Higher or Lower)" problem is a fun and interactive programming challenge. It helps us understand loops, conditions, and user interaction. Problem Statement The program selects a random number, and the user has to guess it. If the guess is too high → show "Too High" If the guess is too low → show "Too Low" If correct → show success message Approach Generate a random number Take input from the user Compare the guess with the actual number Give hints (higher or lower) Repeat until the user guesses correctly Python Code python import random number = random.randint(1, 100) while True: guess = int(input("Enter your guess (1-100): ")) if guess < number: print("Too Low! Try again.") elif guess > number: print("Too High! Try again.") else: print("Congratulations! You guessed correctly.") break ## Example: Enter your guess : 50 Too Low! Try again. Enter your guess : 75 Too High! Try again. Enter your guess: 65 congratulations! you guessed correctly.

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
5 views

Related Articles