Lab, Foundations Projects
7 tasks, easy to hard: Predict, then run, Write it, Complete it, Fix it, Trace it, Refactor it, Mini challenge. Hints come one at a time and you can see each answer. Lab work is saved as practice and earns no XP.
Open the lessonYou can read every task below. Running, checking and saving them needs a free ID.
7 tasks
Task 01 .Type what the program will print, then run it to compare.
Type exactly what this program prints.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 02 .Solve it from the prompt, starting from an empty editor.
Write tip_amount(bill, percent) that returns the tip rounded to 2 decimal places. Print tip_amount(36, 15) and tip_amount(48.6, 10) with two decimals each, giving 5.40 and 4.86.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 03 .Fill the marked gaps in the starter code.
Replace each ___ with an operator so the program splits 10.00 between 3 people in whole cents and prints [334, 333, 333] and True.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 04 .The starter code has a bug. Repair it so the checks pass.
Task 05 .Fill the table with the variable values, step by step.
Each row shows i and paid each time either changes, once both exist. 1,001 cents are shared between 4 people.
cents = 1001
people = 4
base = cents // people
extra = cents % people
paid = 0
for i in range(people):
paid += base + (1 if i < extra else 0)Sign in or create a free ID to fill in and check this table.
Task 06 .Rewrite working code to the stated rule, keeping the same output. Rule: Store the rate once in a TIP_RATE constant and use the name everywhere.
The tip rate 0.15 is typed in three places. Add a constant TIP_RATE = 0.15 at the top and use it everywhere, so the number appears only once. The output must not change.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 07 .A short task that combines this lesson with earlier ones.
Write receipt(bill, percent, names) that returns a list of lines: the bill, the tip and the total as Label: amount, then one line per name with that person's share, splitting the total in whole cents with the extra cents going to the first names. All amounts use two decimals. Print each line of receipt(58.0, 10, ["Ana", "Bo", "Cy"]):
Bill: 58.00 Tip: 5.80 Total: 63.80 Ana: 21.27 Bo: 21.27 Cy: 21.26
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.