Conversion rates without crashing
Mediumtry exceptZeroDivisionErrorround· 20 XP
A marketing report lists each campaign as (name, visitors, signups). Some campaigns haven't had any visitors yet, and dividing by zero crashes the whole report.
Write a function conversion_rates(campaigns) that returns a dictionary mapping each campaign name to signups / visitors rounded to 3 decimals, or to None when there were no visitors. Use try / except ZeroDivisionError.
How it's checked
Your code runs, then the check below runs and its printed output is compared with ours.
conversion_rates([("spring", 200, 9), ("new", 0, 0)])returns{"spring": 0.045, "new": None}
Hints, the later questions and the answer come with Pro.
def conversion_rates(campaigns):
...