Last active
March 25, 2016 02:40
-
-
Save charleyXuTO/7211bd182b858c855540 to your computer and use it in GitHub Desktop.
Guessing Number Game
This file contains 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
import random | |
guessesTaken=0 | |
myname=input("Hello! What is your name?") | |
number=random.randint(1,20) #The number that the user needs to guess | |
print('Well, ' +myname+ ', I am thinking of a number between 1 and 20. You have 5 tries to guess the number. Good luck! :)') | |
while guessesTaken<6: | |
guessed_number=int(input("Guess a number!")) #User inputs here | |
if guessed_number==number: | |
print("Good job! You guessed my number!") | |
break | |
if guessed_number>number: | |
print("Nope. Sorry. The number is lower.") | |
if guessed_number<number: | |
print("Nope. Sorry. The number is higher.") | |
guessesTaken=guessesTaken+1 | |
if guessed_number != number: | |
print("Sorry, my number was " + str(number)) | |
print("Thanks for playing!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment