"""
guessing game -- full implementation
Sally CS Major
Spring 2020
"""
from random import *
def main():
print_intro()
answer = randrange(1,101)
nguesses = 0
done = False
while not done:
nguesses = nguesses + 1
guess = get_int(nguesses)
if guess == answer:
print("Correct!!")
done = True
elif guess > answer:
print("Nope...too high.")
else:
print("Nope...too low")
final_message(nguesses)
def print_intro():
"""
Inputs: None
Returns: None
Purpose: To print an introduction to the user.
"""
msg = """
Welcome to the Ultimate Guessing Game!!!
I'm thinking of a number from 1-100....
Try to guess the number!
"""
print(msg)
def get_int(nguesses):
"""
Inputs: which guess we are on
Returns: integer guessed by user
Purpose: get integer from user, make sure it's valid (1-100)
"""
while True:
n = input("guess #%d: " % (nguesses))
if n.isdigit():
n = int(n)
if n >= 1 and n <= 100:
return n
else:
print("Please guess an integer from 1-100!")
else:
print("Please enter an integer...")
def final_message(nguesses):
"""
Inputs: number of guesses it took
Returns: None
Purpose: display message based on how many guesses it took
"""
print("="*30)
print("Number of guesses it took you: %d" % (nguesses))
if nguesses <= 4:
print("Super!")
elif nguesses <= 8:
print("Not bad.")
else:
print("Better luck next time...")
main()