Created
May 8, 2020 13:31
-
-
Save arpit-omprakash/48e28d5e4b7a597995d57e5c5c689eef 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
#!/usr/bin/env python3 | |
import random | |
guesses_made = 0 | |
name = input('Hello! What is your name?\n') | |
number = random.randint(1,20) | |
print('Well, {}, I am thinking of a number between 1 and 20'.format(name)) | |
won = False | |
while guesses_made < 5: | |
guess = int(input('Take a guess: ')) | |
guesses_made += 1 | |
if guess < number: | |
print("Your guess is too low.") | |
elif guess > number: | |
print("Your guess is too high.") | |
else: | |
print("good job, {}! You guessed my number in {} guesses!".format(name, guesses_made)) | |
won = True | |
break | |
if not won: | |
print("Nope. The number I was thinking of was {}".format(number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment