Last active
November 16, 2022 14:22
-
-
Save courtney-rosenthal/7cceb6b0344cb8297a3da57400cfa93c 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
''' | |
guess_my_number.py - A simple number guessing game. | |
''' | |
import random | |
# Define min and max to the range of numbers for the human to guess. | |
min = 1 | |
max = 10 | |
print("I am thinking of a number between", min, "and", max) | |
print("Can you guess my number?") | |
# Pick a secret, random number for the human to guess | |
secret = random.randint(min, max) | |
#print("The secret number is", secret) | |
# Loop until the game ends. | |
while True: | |
print() | |
ans = input("What is your guess? [type Q to give up and quit] : ") | |
if ans.upper() == 'Q': | |
print("Bye!") | |
break | |
if not ans.isdigit(): | |
print("That is not a valid number! Please try again.") | |
continue | |
guess = int(ans) | |
if guess < secret: | |
print("No. Your guess was too low.") | |
elif guess > secret: | |
print("No. Your guess was too high.") | |
else: | |
print("Correct! You guessed my number!") | |
break | |
# The game is over! | |
print("Thank you for playing my game.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment