Last active
January 12, 2018 23:22
-
-
Save KeronCyst/022bebc4ce6d15f5fd5fb5b30a693b2e 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
import random | |
secret_number = random.randint(1, 100) | |
print("Hello! What is your name?") | |
name = input() | |
print("Hi, " + str(name) + ". I'm thinking of a number between 1 to 100. I'll give you 7 chances to find it.") | |
chances = 7 | |
while True: | |
print("Take a guess.") | |
guess = input() | |
chances -= 1 | |
too_low = "Your guess is too low. " | |
too_high = "Your guess is too high. " | |
chances_left = "Try again. You have " + str(chances) + " chances left. " | |
one_chance_left = "Try again. You only have 1 chance left! " | |
out_of_bounds = "Stay within 1-100, please. " | |
if guess == "debug": | |
chances += 1 | |
print("Secret number: " + str(secret_number) + ". Number of chances left: " + str(chances)) | |
else: | |
try: | |
guess = int(guess) | |
if guess > 100 or guess < 1: | |
chances += 1 | |
print(out_of_bounds, end="") | |
elif chances > 1: | |
if guess == secret_number: | |
break | |
elif guess < secret_number: | |
print(too_low, end="") | |
else: | |
print(too_high, end="") | |
print(chances_left, end="") | |
elif chances == 1: | |
if guess == secret_number: | |
break | |
elif guess < secret_number: | |
print(too_low, end="") | |
else: | |
print(too_high, end="") | |
print(one_chance_left, end="") | |
else: | |
break | |
except ValueError: | |
print("Try typing only a whole number.") | |
chances += 1 | |
if guess == secret_number and chances == 6: | |
print("Wow, " + name + ", you nailed it instantly! My number was " + str(secret_number) + ". Great job!") | |
elif guess == secret_number and chances >= 1: | |
chances += 1 | |
print("Rock on, " + name + "! You guessed my number, " + str(secret_number) + ", with " + str(chances) + " chances left!") | |
elif guess == secret_number: | |
print("Whew, you guessed my number just in the nick of time, " + name + "! It was " + str(secret_number) + ".") | |
else: | |
print("Darn! Sorry to hand it to ya, but my number was " + str(secret_number) + ". Come again?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm wondering about how to consolidate 31-36 and 39-44 which are identical.