Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Last active August 29, 2015 13:57
Show Gist options
  • Save pzp1997/9627988 to your computer and use it in GitHub Desktop.
Save pzp1997/9627988 to your computer and use it in GitHub Desktop.
## Age_Guess.py by Palmer (March 18, 2014)
## Written in Python 3.3.4
## Import statements
from random import randint
## Constants
name = "Bill"
min_age = 1
max_age = 50
guess_lim = 5
## Variables
age = randint(min_age, max_age)
turns = 0
## Program body
print("Age_Guess.py by Palmer (March 18, 2014)")
print("To quit, just input \"quit\" (without the quotation marks) at anytime.")
print()
while True:
guess = input("Guess how old " + name + " is: ")
while not guess.isdigit():
if guess.lower() == "quit" or guess.lower() == "q":
raise SystemExit
else:
print("Your guess must be a counting number.")
guess = input("Guess how old " + name + " is: ")
guess = int(guess)
if turns >= guess_lim-1 and not guess == age:
print("You lose :(. " + name + " was " + str(age) + " years old.")
print()
age = randint(min_age, max_age)
turns = 0
elif guess>max_age:
print(name + " is younger than " + str(max_age) + " years old.")
elif guess<min_age:
print(name + " is older than " + str(min_age) + " years old.")
elif guess>age:
print(name + " isn't that old!")
turns += 1
elif guess<age:
print(name + " is older than that!")
turns += 1
else:
print("You win!")
print()
age = randint(min_age, max_age)
turns = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment