Guessing Game Design Example

Example of a design with stubbed out functions

"""
guessing game design

Sally CS Major
Spring 2020
"""

from random import *

def main():
    print_intro()
    answer = randrange(1,101)
    # for debugging/testing...will delete later
    print(answer)
    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.
    """
    print("Intro to guessing game...")

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)
    """
    # will add validation loop later, make sure number is 1-100
    # will add guess number to prompt later
    n = int(input("your guess: "))
    return n

def final_message(nguesses):
    """
    Inputs: number of guesses it took
    Returns: None
    Purpose: display message based on how many guesses it took
    """
    print("Super.", nguesses)


main()