Lab, In Depth 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 entropy_bits(count, pool_size) that returns count * log2(pool_size) rounded to 1 decimal place. Print it for 8 characters from 26, 12 characters from 62 and 4 words from 7776, so the program prints:
37.6 71.5 51.7
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 ___ with the secrets function that picks one item from a sequence, so the program prints 6 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.
The checker says every password has no digit, even ones that clearly have one. Fix the rule so the program prints:
1 ['shorter than 12', 'no digit', 'no capital'] 2 [] 3 ['shorter than 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 05 .Fill the table with the variable values, step by step.
Each row shows ch, upper and digits each time one of them changes, once all three exist.
upper = 0
digits = 0
for ch in "aB3C":
if ch.isupper():
upper += 1
elif ch.isdigit():
digits += 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 secrets.choice and do not use the random module.
This generator uses the random module, which is predictable. Change it to use secrets.choice and remove every use of random. 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 generate(length, pools) that returns a password of length characters with at least one character from every string in pools, picked with secrets and shuffled securely. If length is smaller than the number of pools, raise ValueError with the message length must be at least N, where N is the number of pools. The program should print:
length ok: True every pool used: True all different: True error: length must be at least 4
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.