Skip to content

Assignment: I Am Thinking of a Number...Line By Line Walkthrough

sleepinghungry edited this page Mar 7, 2017 · 4 revisions

###Line By Line Walkthrough

Line 1:

Create a variable that will keep track of whether the game is over or not, and then set it to a boolean value (either True or False). This will be used in Line 2 to either keep the game going or end the game.

Line 2:

Use the while keyword, the variable you created above, and a colon to start the while statement. You may or may not want to use the not keyword to negate your variable from Line 1. Examples:

If you named your Line 1 variable game_over and set it to False:

game_over = False

Your while statement would look like this:

while not game_over:

Because you want the program to keep looping if the game is NOT over.

But, if you named your Line 1 variable still_guessing and set it to True:

still_guessing = True

Your while statement would look like this:

while still_guessing:

Because you want the game to keep going while the user is still guessing.

Line 3:

Create a variable that will store the guess prompted by the input() command. In the input() command, include text to ask a user for a number.

Line 4:

Use the int() command to turn the guess from text into a integer. And then store that integer into the variable you created in Line 3.

Line 5:

Use the if keyword, your guess variable, the less than operator, the correct number, and a colon to start the if statement.

Line 6:

Use an indent and a print() command to let the user know the guess was too low.

Line 7:

Use the elif keyword, your guess variable, the greater than operator, the correct number, and a colon to start the elif statement

Line 8:

Use an indent and a print() command to let the user know the guess was too high.

Line 9:

Use the else keyword and a colon to start the else statement

Line 10:

Use an indent and a print() command to let the user know the guess was correct.

Line 11:

Use an indent and change your variable from Line 1 (set it to the opposite value you initially set it to) to end the game.

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