Homework 10 — Intro to Python
Skills: 7, 8
Due
Thursday, November 13, 2025 at 6PM (Oakland) or 9PM (Boston)
Submission
This HW, which is in Python, is done via VSCode on your computer, and submitted to Github via the Source Control tab. Go to Pawtograder to find the repository, which you can clone locall to do the assignment. Commits automatically make submissions, and feedback can be viewed on Pawtograder.
NOTE
The handout accidentally has the test_assignment.py file from HW11. Please replace the contents of that file with the following before you start.
def test_lemonade_stand_1():
pass
# ... add more tests here
def test_lemonade_stand_2():
pass
# ... add more tests here
def test_which_stand_better():
pass
# ... add more tests here
def test_tick():
pass
# ... add more tests here
def test_add_prefix():
pass
# ... add more tests here
def test_remove_odd_length_strings():
pass
# ... add more tests here
Problem 1
The weather is cooling down in Boston, but over the summer, you noticed a lot of kids selling lemonade at little stands. You noticed two that were next to each other that had different pricing and different materials. You were curious which strategy would work better, so in this problem you will model both stands.
Part A
The first stand was getting 16 fluid ounce bottles of lemonade from a shop right around the corner, for $2/each, and was selling 4 fluid ounce cups for $1/each. For simplicity, we'll ignore the cost of the cups, refridgeration, etc, and you can assume the corner shop never runs out of 16 fluid ounce bottles.
Design a function lemonade_stand_1 that takes a number of cups sold as
input and returns the total profit. Be sure to take into account that the 16
fluid ounce bottles cannot be purchased in part, so there may be extra left
over! Hint: the python operator % (which calculates the remainder of division)
may be useful.
Part B
The second stand decided to buy the lemonade in bulk, getting a gigantic 5 gallon (640 fluid ounce) container for $20. To try to undercut the other stand, they decided to sell their 4 fluid ounce cups for $0.75 each. But, since they bought their lemonade from a store that is far from home, when they run out, they will stop being able to sell lemonade.
Design a function lemonade_stand_2 that takes a number of cups (attempted
to be) sold as input and returns the total profit. Note that this input may
be any positive integer, so if it exceeds their capacity, the function should
simply return their profit before they closed the stand. Note that if they
sell the entirety of their lemonade, there is no penalty for being unable to
sell additional cups. As before, we aren't considering cost of cups,
refridgeration, etc.
Part C
Now, you'd like to design a function which_stand_better that, given a
number of cups sold, returns the number 1 if lemonade stand 1 would make more
money at that number of cups, or 2 if lemonade stand 2 would make more money
with that number of cups sold. If they are tied, return 0.
Problem 2
Translate your tick function from Homework 2 into Python.
Problem 3
Design a function add_prefix that takes a string (the prefix) and a list of strings and returns
a list of strings where each element in the input has had the prefix added in front of it.
Problem 4
Design a function remove_odd_length_strings that takes a list of strings and returns a list
that only includes those in the input whose length is even (evenly divisible by 2). len(str) returns the length of a string in Python, and n % m is the remainder operator.
Problem 5
Currently, this program prints 10. We'd like you to add one line that includes the global keyword to the program (do not change or remove any existing lines, and you may only add that one line) that causes it to print 50 instead.
x = 10
def f(x : int) -> int:
""" the f function """
x = x + 20
return x
def g(y : int) -> None:
""" the g function """
x = f(y)
g(30)
print(x)