Your task
Write a rate function and test both ordinary and undefined cases. Explain the expected output before running the code.
Hint
Read with csv.DictReader so column names are explicit. CSV values are strings until converted. Keep parsing failures visible.
Worked solution
54/900 is 0.06. A zero denominator returns None, meaning unavailable, rather than claiming a 0% measured conversion rate. Validate nonnegative counts separately.
import csv
with open('retail-orders.csv',newline='',encoding='utf-8') as f:
rows=list(csv.DictReader(f))
def rate(numerator,denominator):
if denominator==0: return None
return numerator/denominator
assert rate(54,900)==0.06
assert rate(0,0) is NoneExtend the test
Change one input in a disposable copy and predict which check should fail. Restore the original before comparing results.
Try the activity before reading its reference. Keep your sources, commands and assumptions with your work. Companion activities are unsaved self-practice and do not award a certificate or change lesson progress.