Developers as Decision-Makers
This lab is adapted from an activity created by Evan Peck (Bucknell University).
It’s common for us to talk about algorithms as “making decisions.” But algorithms don’t really have judgment or the ability to reason about the pros and cons of a specific case. As you know, algorithms do nothing more or less than exactly what we, the programmers, tell them to do. It is our responsibility to decide what rules and mechanisms the algorithm will use in its decision process.
When we talk about an algorithm making decisions, we are really talking about writers of software making decisions.
The decisions we make in code impact the lives of real people. For example, the Silicon Valley Triage Tool is an algorithm that identifies homeless people for whom giving them housing would cost the public less than keeping them homeless. So even as we learn the simple structures of code, we need to think about how can we make good decisions as program designers? When the livelihood of people depend on us, how can we be fair?
We’re going to explore this idea in a context that might be more familiar to you – college housing. Colleges like Middlebury select methods that determine the order in which students can choose their housing. You might not think of it this way, but this is an automated, systematic method for solving a problem: an algorithm. In this lab, you’ll have the opportunity to design your own algorithm. We’re also going to briefly explore the human-centered design process to ensure that the decisions we make as algorithm designers are never untethered from the people we impact.
In this lab, you’ll practice:
- Writing English descriptions of decision-making procedures and translating them into code.
- Soliciting text input from users.
- Applying conditionals (
if
,elif
, andelse
) to control program execution. - Using accumulation variables to keep track of information inside a program.
- Testing your algorithm and seeking feedback from the people whom it will impact.
Lab Template File
Here is the template file you should download in order to complete this activity. You and your partner expected to (a) work together on the lab and (b) submit your own files individually on Gradescope, acknowledging each other’s collaboration.
If you are having trouble accessing the template file, you can also try this link.
In either case, highlight all the text, copy it, and paste it into a blank Thonny file.
Who Chooses Housing First?
Every year, Middlebury students select their housing for the following year. Your job is to build an algorithm that will help determine the order in which students get to select their housing. To keep things manageable, we’re going to use a point system:
- Students are awarded a number of points based on a variety of factors.
- Students with the most points get the first choice of housing.
This is a real approach used by many colleges and universities. For example, the following is a real point system used by another liberal arts college in the US:
- Current Freshman: 1 point
- Current Sophomore: 2 points
- Current Junior: 3 points
- Current Senior: 4 points
- 23+ Years of Age: 1 point
- Full-time, Off-Campus Program credit (e.g. student teaching): 1 point
- Academic Probation: -1 point
- Academic Suspension: -2 points
- On Disciplinary Probation at Any Time During the Academic Year: -3 points
For example, a junior (3 points) who ise 23 years old (1 point) would have priority over a senior (4 points) who has on academic probation (-1 point).
Your goal: Create a program that assigns points to students in order to prioritize them in housing selection.
But wait! Don’t start yet. First…
Before You Code, Assess the Needs of Your Users
That list up there was one college’s approach to prioritizing students for housing. But there are many more aspects to consider if you want your algorithm to be fair and equitable for the diverse needs of students at Middlebury. So, you need to learn more about what those needs are. This is an illustration of a fundamental principle:
Never create a program that serves people without listening to those people about what they need.
This principle is part of a broad design philosophy called human-centered design.
Design and Plan Your Algorithm
Now it’s time to take the needs of your users (other students) and translate them into a concrete algorithm. You should choose at least 5 factors, of which at least three must be from your discussion with other students in the previous activity. That is, you shouldn’t just use factors from the example from the other liberal arts college. You don’t have to use all the ideas from the previous part.
Your algorithm will:
- Ask questions of the user (e.g. What class year are you?)
- Assign points based on their answers (e.g. 4 points if user answered “rising senior”)
- Accumulate their total points across all answers and display the result (like: You have 23 housing points)
Specifications: We are exercising our ability to write code in addition to designing high-level algorithms, so we’re going to put some constraints to make sure you get practice with the different ways in which conditionals can be used.
- You must have at least one question that only appears if the previous question is answered in a specific way.
- For example: if someone says they are a 4th year student, you may ask the question “Are you about to graduate?” If they say yes, they receive no points. ONLY a 4th year student would receive this question.
- Hint: Nested
if
statements.
- You must have at least one question that makes use of a simple mathematical calculation to determine the number of points awarded.
- For example: Rather than ask people to enter their status as a 1st, 2nd, 3rd, 4th year, you ask them for the number of credits they have received so far at Middlebury. Then they might receive
credits/8
points.
- For example: Rather than ask people to enter their status as a 1st, 2nd, 3rd, 4th year, you ask them for the number of credits they have received so far at Middlebury. Then they might receive
- You must have at least one question that use an
if
-elif
-else
structure.
Before You Code, Make Sure It Works: User Testing
Do not create a program that serves people without testing it on people.
Automate Your Decision-Making Process
Ok, finally time to code.
Below, I’ve included a program (unmodified from the original version by Evan Peck at Bucknell) that illustrates some useful coding patterns. It implements part of the example point system shown earlier. You are welcome to use this program as a base for your own, or start from scratch.
# Created by: Evan Peck (Bucknell University)
# - Contact: evan.peck@bucknell.edu
# - Last Modified: April 6, 2019
# Keeps track of the point total during questions
= 0
current_score
# A header to start the program
print("-------------------------------")
print(" HOUSING SCORE CALCULATOR")
print("-------------------------------")
print()
# Assign points based on class year
print("QUESTION 1")
= input("What year are you? (1, 2, 3, 4): ")
year_ans
if year_ans == "1":
+= 1
current_score elif year_ans == "2":
+= 2
current_score elif year_ans == "3":
+= 3
current_score elif year_ans == "4":
+= 4
current_score
# If the student is >= 23 years old, give them another point
= input("How old are you?: ")
years_old
if int(years_old) >= 23:
+= 1
current_score
# At the end of the program, tell the user their score
print()
print("------YOUR HOUSING SCORE----------")
print("Your housing points score is", current_score)
print("----------------------------------")
Your Code Works…But Is It Fair?
You should never deploy real code without checking your assumptions. Your test cases tested your technical assumptions, but not your social assumptions:

Submit Your Work
Finally, one group member should download the lab file and submit it on Gradescope, making sure to add both of you to the submission file to ensure that you both receive credit for your work.
© Philip Claude Caplan, Andrea Vaccari, and Phil Chodrow, 2022