Introduction to Computer Science/3.12: Major Assessment - "Guess the Number" Game

3.12: Major Assessment - "Guess the Number" Game

🎯 Project Goals
  • Apply your knowledge of control structures (while and if/elif/else) to create a complete, interactive program.
  • Use the random module to generate a random number.
  • Practice a full development cycle: planning, coding, and testing.
  • Create a user-friendly experience with clear prompts and feedback.

Major Assessment: "Guess the Number" Game (10%)

This is your major project for Unit 3. You will create a complete, playable "Guess the Number" game. This project is a classic for a reason: it's impossible to build without a solid understanding of loops and conditional logic, and it's a lot of fun to make!

Core Requirements

Your program must do the following:

  1. Generate a Secret Number: At the start, the program must generate a secret random integer between 1 and 100.
  2. Loop for Guesses: The program must repeatedly ask the user to enter a guess until they get the right answer. A while loop is the perfect tool for this.
  3. Provide Feedback: Inside the loop, you must use an if/elif/else chain to check the user's guess and print one of three messages: "Too high!", "Too low!", or "You got it!".
  4. End the Game: When the user guesses correctly, the loop must stop, and the program should print a final congratulatory message.
  5. User-Friendly Interface: Your prompts and feedback should be clear and easy for a user to understand.
  6. Code Quality: Your code must be well-commented (including your name and date) and use clear variable names.

Example Gameplay:

I'm thinking of a number between 1 and 100.
Enter your guess: 50
Too low!
Enter your guess: 75
Too high!
Enter your guess: 62
You got it! Congratulations!

Ideas for Extensions (Level 4+)

Looking for a challenge? Try adding one of these features:

  • Count the number of guesses it took the user to win and display it at the end.
  • Limit the user to a certain number of guesses (e.g., 7 tries).
  • After the game ends, ask the user if they want to play again.

Submission

Submit your final, working .py file or URL.

A Hint to Get You Started

You'll need to use the random module. At the top of your file, you'll need import random. The line to generate your secret number will look like this: secret_number = random.randint(1, 100). Good luck!