print(get_digit(28)) # 2
print(get_digit(91)) # 9
print(get_digit(10)) # 1
print(cube(2)) # 8
print(cube(3)) # 27
print(cube(1)) # 1
Module 3 Assignments
Short Project 02
Due date: Wednesday, September 17, 2025 at 9pm
Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet in Short Project Dates and Instructions.
Programming Problems
Programming Problems should be submitted to gradescope.
Due date: Wednesday, September 17, 2025 at 9pm
Programming Problem 5
Write two python functions. The first function does the following:
- Its name is
get_digit
. - This function takes an integer as input.
- It returns the first digit (from the left) of a two-digit number.
The second function cube
takes an integer n as input. It returns the cube of that number (i.e., n * n * n).
In the main
function, call the get_digit
to get the number and then call cube
to calculate the cube of that number. Finally, print the result.
Name the program cube.py
. You are only allowed to use operations learned in the class. Make sure that gradescope gives you the points for passing the test cases.
Development test cases:
Programming Problem 6
Write two python functions.
The first function,
calculate_tax
, takes an integer as input. It uses a tax rate of0.07
and returns the product of the input and the tax rate.The second function,
calculate_total
, takes three integers as input: the number ofcupcakes
,croissants
, andbagels
. The price of a cupcake is3.5
, a croissant is5.0
, and a bagel is2.5
. It calculates the total cost of the items a customer will buy, including tax. The function returns the total rounded to two decimal places.
In the main
function, call the calculate_total
to get the total cost and print the result.
Name the program bakery.py
. You are only allowed to use operations learned in the class. Make sure that gradescope gives you the points for passing the test cases.
Development test cases:
= calculate_total(5, 1, 6)
total_after_tax print(total_after_tax) # 40.12
print(calculate_total(0, 3, 0)) # 16.05