05/08/2026, 18:36
Basic Page
The solutions are provided at the end of this page.
Exercise 1
Consider the problem of calculating the earning of an employee in a given week. Employees are paid
an hourly rate of $25.56 per hour. If an employee worked overtime (i.e., more than 37.5 hours per
week), they would be paid at a rate of $30.89 per hour for overtime. Write a Python program,
called weeklypay.py, to determine the earning of an employee for a given work week of 45 hours.
The program shall also display both the base-earning portion, the overtime earning portion and the
percentage of the total earning that is contributed by the overtime work.
Exercise 2
Write a Python program to be called packing.py to compute the number of boxes that would be
needed to package 230 cookies, as well as the number of unpacked leftover cookies. Note that
cookie boxes must contain exactly 12 cookies each.
Exercise 3
Write a Python program to be called circumference.py to compute and print the circumference of a
circle inscribed in a square having an area of 200 m2. Note that Pi is 3.14.
Exercise 4
John took a student loan of $7,000 with an interest of 1.2%, applied yearly after their graduation.
John makes one payment of $1000 at the end of each year to repay his loan. The yearly payment is
made after the interest charge is applied. Write a program called my_loan.py to compute and print
the following:
1.
The loan balance owed by the end of the second year after graduation (after the yearly payment
and application of interest charges).
2.
The total interest charge accumulated by the end of the second year after graduation.
3.
The total amount John paid by the end of the second year, after graduation, towards the
repayment of the loan
Exercise 5
Write and run the grade_parse.py program, given below. Verify that the program yields the
output, shown below, for the input: “John Doe, 76, B”. Study the code and add comments as
appropriate to explain the functional behavior of the program.
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
1/7
05/08/2026, 18:36
Basic Page
Exercise 6
Write and run the program datatypes.py, given below. After inspecting the code in relation to the
program’s output, add comments to the code to explain the observed behaviour. In particular,
explain the difference between the divisions involving 7, 7.0,"7", "7.0", and ‘7’.
Exercise 7
Write a Python program called cfreq.py to find how many characters follow the second occurrence
of the second letter in an input string. The following example illustrates the functional behavior of
the program:
Enter input phrase:
After many failures success was inevitable
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
2/7
05/08/2026, 18:36
Basic Page
After many failures success was inevitable
Second letter: f
Second occurrence of f at 11
30 Characters follow the 2nd occurrence of f
Exercise 8
Write a Python program called inventory.py to compute and print the inventory value of a given
product stock stored in a warehouse. The input to the program is a comma separated inventory
record string comprised of the product name, unit price, quantity, and depreciation status. The
following is an example inventory record string:
Table, 20, 34.78, 0
The depreciation status may only take the values 0 or 1. Since the depreciation status for the
example above is 0, the inventory value of the product stock in question is equal to the unit price
times the quantity, which is 20*34.78= $695.6. However, if the depreciation status is 1, the
inventory value of the product stock should be calculated using a 10% discount on the unit price.
For an input record string Desk, 10, 100.21, 1, the inventory value of the stock is 10*100.21*0.9=
$901.89.
The following are two examples highlighting the expected behavior of the program.
Solutions
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
3/7
05/08/2026, 18:36
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
Basic Page
4/7
05/08/2026, 18:36
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
Basic Page
5/7
05/08/2026, 18:36
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
Basic Page
6/7
05/08/2026, 18:36
Basic Page
© Copyright Youcef Derbal, 2024
https://courses.torontomu.ca/d2l/le/content/1166414/viewContent/6980317/View
7/7