Created
April 30, 2020 13:42
-
-
Save Raj39120/c65b1c22343a682d252ccfc40340f32e to your computer and use it in GitHub Desktop.
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
def game(): | |
def actual_game(): | |
import random | |
print("This is a guessing game. If you want to exit the game at any time, type exit surrounded by quotes.") | |
print("The computer has generate a random integer between 1 and 9 and including 1 and 9.") | |
number = random.randint(1, 9) | |
guess = 0 | |
count = 0 | |
while guess != number and guess != "exit": | |
guess = input("Enter you guess of what the number is over here: ") | |
if type(guess) == float: | |
print("Please enter an integer. You should've put " + str(int(guess)) + " and (not " + str(guess) + ")") | |
return | |
if guess == "exit": | |
break | |
guess = int(guess) | |
count += 1 | |
if guess < number: | |
print("Too low!") | |
elif guess > number: | |
print("Too high!") | |
else: | |
print("You got it!") | |
print("And it only took you", count, "tries!") | |
actual_game() | |
actual_game() | |
game() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment