Created
October 25, 2018 03:39
-
-
Save Ricket/bed461b159aac355a3f9f7671ef18c52 to your computer and use it in GitHub Desktop.
Guess-the-number script for teaching programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('I am thinking of a number between 1 and 20...') | |
import random | |
secret_number = random.randint(1, 20) | |
tries = 0 | |
winner = False | |
while tries < 6 and not winner: | |
guess = input('Take a guess: ') | |
guess_number = int(guess) | |
tries = tries + 1 | |
if guess_number < secret_number: | |
print('You guessed too low') | |
if guess_number > secret_number: | |
print('You guessed too high') | |
if guess_number == secret_number: | |
winner = True | |
if winner: | |
print('You win!') | |
else: | |
print('Your 6 tries are up... You lose!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment