Lab, Functions
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. Watch which function returns and which one only 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 a function make_greeting(name) that returns the string Hello, NAME! with the given name. Then print the result for "Ada" and "Linus".
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 rectangle_area returns the width times the height.
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.
average should return the mean of a list so the program prints Average: 6.0 and Above: True. It prints instead of returning. Fix it.
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 i and total each time either changes, once both exist. The function's own variable n is not in the table.
def triple(n):
return n * 3
total = 0
for i in range(1, 4):
total = total + triple(i)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: Write the formula once inside a function called circle_area and call it three times.
The same circle area formula is written three times. Define a function circle_area(radius) that returns 3.14159 * radius * radius rounded to 1 place, and use it for all three prints. The formula should appear 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 has_digit(text), which returns True if any character is a digit, and check_password(password), which returns one message: too short for fewer than 8 characters, needs a digit if has_digit is false, otherwise ok. Print the result for each password in the list so the output is:
cat: too short sunflower: needs a digit sunflower7: ok
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.