Technicalities of My Programming Project

For my Programming Cumulative Project, I decided to do a Buzzfeed type Personality Quiz that will tell the user which Lincoln Lutheran teacher they are.  The source code was based on mostly things that I had already learned how to do, except for one thing- the dictionary function, which I’ll get more into in the next paragraph.  The output provides the user with their result, along with a short 1-2 sentence description of the teacher they are most like.

Most of the concepts that I used for my program were ones that we had learned already in this class, such as if statements, while loops, for loops, print statements, booleans, and variables.  However, in order for my program to not be thousands of lines of code and for me to not have to pass 17 variables back and forth, I had to learn how to use a Dictionary Function.  Basically what this does is it allows you to create a “file” (not really a file) of sorts with {} brackets, then you can put certain things into the dictionary- in my case, teachers- so that you can just pass the dictionary back and forth instead of a ton of other variables into other procedures.  This was super useful for my program in particular because I could add points to the values in the dictionary because I set the point level as 0 for all the teachers when I created the dictionary. 

Below are some snippets of code that I am proud of.  The first one is my dictionary function that goes through all of the values in the dictionary and figure out which teacher has the most points.  I am mostly proud of this because when Mr. Sommerer was helping me write it and understand the dictionary, I understood what was going on in the code and what he was doing.  First, you set the variable most as ‘none’, so then a teacher can eventually take the place of that string.  Then, you set mostPoints as 0 so that any point value is greater than it.  Then, while the teacherResult is in the teacher dictionary, if the teacher has more points than 0, it becomes the new most.  This function will go through all the teachers, replacing the ‘most’ variable until it has the teacher with the most points.

def get_result(teachers):
    """Gets the result for the teacher the user is most like."""
    #
    # Set parameters for most and most points to base
    # teacher numbers off of.
    #
    most = 'none'
    mostPoints = 0
    for teacherResult in teachers:
        if teachers[teacherResult] > mostPoints:
            most = teacherResult
            mostPoints = teachers[teacherResult]
            teacherResult = most
    return most, mostPoints, teacherResult

 

The second snippet of code is just the function that creates the dictionary.  I am proud of this because I had to learn something new and use it successfully, and I did.  The empty dictionary is formed with the {} brackets, then the lines of code below that are where I added teachers to the dictionary.  I then set their point values as 0 so I could add more as the user answered each question.

def make_teacher_dictionary():
    """Make a dictionary for all of the teachers so that adding up point totals is easier."""
    #
    # Create a dictionary for all the teachers to be able to 
    # add up points without passing 17 variables back and forth.
    #
    teachers = {}
    teachers['ziems'] = 0
    teachers['mchargue'] = 0
    teachers['bassett'] = 0
    teachers['duitsman'] = 0
    teachers['troyer'] = 0
    teachers['stahr'] =  0
    teachers['kollbaum'] = 0
    teachers['werner'] = 0
    teachers['schoettlin']  = 0
    teachers['rickords'] = 0
    teachers['seitz'] =  0
    teachers['bartelt'] = 0
    teachers['warrick'] = 0
    teachers['snyder']  = 0
    teachers['stumpf'] = 0
    teachers['deeter'] = 0
    teachers['ziegler'] = 0
    teachers['sommerer'] = 0
    return teachers

 

These next couple snippets of code are ones that I’m not necessarily proud of or that I think I could’ve done better, given more time.  The first one is part of the last function I wrote, where I just had a bunch of print statements that printed based on which teacher the user was most like.  If I had more time, I would have written these in a file and then imported the file into the program to write it out so that the function wouldn’t be as overbearing, long, and repetitive.

def give_result(most):
    """Print messages based on the result of the quiz."""
    if most == 'bassett':
        print("""Congratulations! You are most like Mr. Bassett!
He teaches Social Studies and Religion classes here at Lincoln Lutheran
and enjoys making fun of Colten Waldo.""")
    elif most == 'ziems':
        print("""Congratulations! You are most like Mr. Ziems!
He teaches Science and Religion classes here at Lincoln Lutheran
and enjoy dissecting dead animals and looking at yeast under a
microscope.""")
    elif most == 'mchargue':
        print("""Congratulations! You are most like Mrs. McHargue!
She teaches Spanish Classes here at Lincoln Lutheran and definitely
loves her coffee!""")

 

The second one is the first question function that I wrote.  The reason that I included this in the snippets of code that I’m not as proud of is because I wish I would have been able to use graphics for this part to make it look a little cooler.  I maybe could have, but I knew that it would be hard to add graphics after I had written the function and the whole program.  I wish that I would have decided to add graphics from the very beginning instead of wanting to do it at the very end.

def question_one():
    """Asks the user what their favorite class is."""
    print("===============================================")
    print("Which of these is your favorite class at Lincoln Lutheran so far?")
    print()
    sleep(1)
    print("""1. Biology
2. Spanish
3. History
4. English
5. Math
6. Foods/Sewing
7. Band
8. Religion
9. Art
10. Choir
11. Chemistry
12. Physical Education
13. Programming""")

 

Leave a Reply

Your email address will not be published. Required fields are marked *