Example of top-down design

Notice that the main program is complete, while the rest of the functions are merely stubbed out. The interface of each function has been defined, i.e. how many and what types of parameters are expected as well as what will be returned, but the functions have not yet been implemented. Comments have been included inside the function definitions as reminders for how we expect to implement them.

# This program simulates the Pennsylvania Lottery game known as Big 4.
# A player must select four numbers between 0 and 9, and will win if
# the four numbers come up in any order.  This program estimates the
# probability of winning. 

from random import *

def main():
    intro()
    n = input("Enter the number of lotteries to try: ")
    avg = simulateNLotteries(n)
    print "The odds of winning are", 1/float(avg)
    
def intro():
    """
    Inputs:  None
    Returns: None
    Prints an introduction to the program.
    """
    return

def pick4():
    """
    Inputs:  None
    Returns: A list of four random integers between 0 and 9 inclusive.
    """
    # use a list accumulator pattern
    return [1,2,3,4]
    
def sameValues(l1, l2):
    """
    Inputs:  Two lists
    Returns: True if the values in the two given lists are the same,
    but not necessarily in the same order.  Otherwise False.
    """
    # sort the lists and then check if they are equivalent
    return True

def simulateLottery():
    """
    Inputs:  None
    Returns: An integer representing the number of tries it took to match
    a selected goal of four lottery numbers.
    """
    # use pick4 to set the goal
    # use a while loop to continue to pick4 until there is a match
    # count the number of iterations of the loop
    return 10

def simulateNLotteries(n):
    """
    Inputs:  An integer n representing the number of lotteries to simulate.
    Returns: A float representing an average of the number of times it took
    to get a match.
    """
    # repeatedly call simulateLottery and accumulate an average
    return 100.0


main()