Skip to content

Assignment: Guess a Number

sleepinghungry edited this page Mar 7, 2017 · 1 revision

I am Thinking of a Number...

In this assignment, you will write a program that will repeatedly ask a user to guess a number between 0 and 20, until the user guesses the correct number.

##Functional Requirements

  1. User must be prompted for a guess between 0 and 20.
  2. User must be told if his guess is too low or too high.
  3. User will be prompted again if the guess is incorrect.
  4. User must be told if his guess is correct.
  5. The game ends when the user guesses the correct answer.

##Code Requirements (and hints)

  1. You must use a boolean variable (one that holds either True or False) to store whether the game is over.
  2. You must use a while statement to repeatedly ask the user for the correct answer.
  3. You must use an if statement inside the while statement to determine whether the answer is correct or not.

##Enhancements

  1. Use the random module to have your program set the secret_number variable at the beginning of the game. THen use that variable for comparison's sake. You will need the following two lines at the top of your code: import random secret_number = random.randomint(0,20)

  2. Use another variable to keep track of how many guesses it takes for the user to get the correct answer. At the end of the game, tell the user how many guesses were made.

  3. Instead of using a range from 0 to 20, ask the user to input the maximum end of the range. Then use that input to generate a random number.

BWX Game Engine pages

Python Pages

Step By Step Guides

Building Conditionals

Lectures

Explaining Conditionals

Assignments

I Am Thinking of a Number...

Clone this wiki locally