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.
Start with value = 1. Use a while loop to keep doubling it while it is less than 100, printing each value on its own line. The output is 1, 2, 4 and so on up to 64.
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 ___ so the loop prints the numbers 1 to 10 except multiples of 4, all on one line: 1 2 3 5 6 7 9 10.
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 program should print Lap 1 to Lap 5 and then Race over, but it stops one lap early. Fix the loop.
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 n and steps each time either changes, once both exist. Follow the loop until it stops.
n = 20
steps = 0
while n > 1:
n = n // 2
steps += 1Sign 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: Stop the loop with break instead of tracking a found flag.
This search keeps a found flag and keeps looping after it has found the answer. Rewrite it with a for loop and break, and no found variable. The output must stay First over 50: 64.
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.
Start with n = 6. While n is not 1: if it is even, halve it with //; otherwise make it 3 * n + 1. Print every value on one line joined by -> , then print how many steps it took:
6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1Steps: 8
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.