Last active
December 22, 2015 20:49
-
-
Save ramalho/6528571 to your computer and use it in GitHub Desktop.
Simple number guessing game
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
| #!/usr/bin/env python3 | |
| # guess.py: a simple number guessing game | |
| from random import randint | |
| print('Hello, please type your name:') | |
| name = input() | |
| print('Hi, ', name, '!', sep='') | |
| print("I will select a number from 1 to what number? You can choose, dear user.") | |
| upperbound = int(input()) | |
| print("Ok. Let's see if you guess it.") | |
| number = randint(1, upperbound) | |
| tries = 0 | |
| while tries < 10: | |
| tries = tries + 1 | |
| print('Take a guess:') | |
| guess = int(input()) | |
| if guess == number: | |
| if tries == 1: | |
| print('You guessed it, ' + name + '! It took you ' + str(tries) + " try.") | |
| else: | |
| print('You guessed it, ' + name + '! It took you ' + str(tries) + " tries.") | |
| break | |
| elif guess > number: | |
| print('Too high.') | |
| else: | |
| print('Too low.') | |
| else: | |
| print('The correct number was:', number) | |
| print('Game over') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment