-
Notifications
You must be signed in to change notification settings - Fork 1
Assignment: I Am Thinking of a Number...Line By Line Walkthrough
###Line By Line Walkthrough
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.
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.
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.
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.
Use the if keyword, your guess variable, the less than operator, the correct number, and a colon to start the if statement.
Use an indent and a print() command to let the user know the guess was too low.
Use the elif keyword, your guess variable, the greater than operator, the correct number, and a colon to start the elif statement
Use an indent and a print() command to let the user know the guess was too high.
Use the else keyword and a colon to start the else statement
Use an indent and a print() command to let the user know the guess was correct.
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.