-
-
Save dildev/7f8f1da8baa972acd295 to your computer and use it in GitHub Desktop.
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
#This is a guess the number game | |
import random | |
import time | |
guessesTaken = 0 | |
print('Hello! What is your name?') | |
myName = input() | |
number = random.randint(1,20) | |
print('Well, '+myName+', I am thinking of a number between 1 and 20.') | |
while guessesTaken < 6: | |
print('Take a guess.') | |
#There are four spaces in front of print. | |
guess = input() | |
guess = int(guess) | |
guessesTaken = guessesTaken + 1 | |
if guess < number: | |
print('Your guess is too low.') | |
#There are eight spaces in front of print. | |
if guess > number: | |
print('Your guess is too high.') | |
if guess == number: | |
break | |
if guess == number: | |
guessesTaken = str(guessesTaken) | |
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!') | |
if guess != number: | |
number = str(number) | |
print('Nope. The number I was thinking of was ' + number) | |
time.sleep(3) | |
#Make sure to import random and time before trying to use either. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment