DEV Community

Cover image for Day 11 of My AI & Data Mastery Journey: From Python to Generative AI
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 11 of My AI & Data Mastery Journey: From Python to Generative AI

*PROJECT :- *

Number Guessing Game

Display the Game Logo

Print ASCII art of the "Number Guessing Game" banner.

Initialize Variables

 Set variable Attempt = 0.
Enter fullscreen mode Exit fullscreen mode

Define Function: choice(number)

Ask the user to choose a difficulty level — type 'easy' or 'hard'.

If user chooses 'easy', set Attempt = 10.

If user chooses 'hard', set Attempt = 5.

If user enters anything else, display “Invalid choice”.
Enter fullscreen mode Exit fullscreen mode

Start Guessing Loop

- For each attempt from 1 to Attempt:

   - Ask the user to input their guess number.

   - If guessed number equals the hidden number:

        -Display “Correct! You got it!” and stop the game.

   -If guessed number is less than the hidden number:

        Display “Too low!”

   -If guessed number is greater than the hidden number:

        Display “Too high!”

   -Show remaining attempts: “You have (Attempt - i) attempts     left.”

-If the user runs out of attempts:

   -Display “You’ve run out of guesses. Restart the game to try again.”

   -End the game.
Enter fullscreen mode Exit fullscreen mode

Define Function: main()

Display welcome messages:

    -“Welcome to the Number Guessing Game!”

    -“I’m thinking of a number between 1 and 100.”

Randomly select a number between 1 and 100, store it in number.

(Optionally display the number for testing.)

Call choice(number) to start the guessing process.
Enter fullscreen mode Exit fullscreen mode

Program Execution

If file is run directly:

Call main() to start the game.

Game Rules
The secret number is randomly selected from 1–100.

Players can pick “easy” (10 attempts) or “hard” (5 attempts).

The game provides feedback (“Too high!” / “Too low!”) after each guess.

The game ends when the correct number is guessed or all attempts are used.

Top comments (0)