Lab, Functional Tools and Modules
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.
Import math and write hypotenuse(a, b), which returns the square root of a * a + b * b. Print hypotenuse(3, 4) and hypotenuse(5, 12).
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 ___ so the program can call median and mode without a prefix.
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 the area of a circle with radius 2, rounded to 2 places: 12.57. It raises a NameError. Fix it without changing the import 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.
This file is run directly. Each row shows total and count each time one of them changes, once both exist.
import math
total = 0
count = 0
if __name__ == "__main__":
for n in [4, 9, 16]:
total = total + math.isqrt(n)
count = count + 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: Use import math and call every math name with the math. prefix; no import *.
This code works, but from math import * hides where names come from. Rewrite it to use import math and the math. prefix. 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 letter(score) that returns A for 80 or more, B for 60 or more and C otherwise, and report(scores) that returns a string like mean 71.7, grades ABC using statistics.mean rounded to 1 place. Put the printing under a __name__ guard so the file could be imported without output, and print the reports for [85, 75, 55] and [90, 90]. Run directly it should print:
mean 71.7, grades ABC mean 90, grades AA
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.