Lab, Operators and Control Flow
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.
The user's answers are already stored: name = "Priya" and town = "York". Use one f-string to print Hi Priya, welcome to York!
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 a format specification so the program prints Price: 7.50 and Sold: 12,400.
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.
The variable typed holds what a user typed, as input() would return it. The program should print Next year: 15 but stops with an error. Fix it without changing the first line.
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 05 .Fill the table with the variable values, step by step.
Each row shows answer and total each time either changes, once both exist. Text is shown in quotes.
total = 0 answer = "4" total = total + int(answer) answer = "10" total = total + int(answer)
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: Use an f-string instead of + and str().
This line builds its message with + and str(). Rewrite it as one f-string. The output must stay Sam has 3 cats and 2 dogs.
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.
Print a receipt where item names are left aligned in 10 characters and prices are right aligned in 7 characters with two decimal places. Then print the total the same way. The items are Bread 1.2, Milk 0.95 and Jam 2.5. The output is:
Bread 1.20 Milk 0.95 Jam 2.50 Total 4.65
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.