An old copy that hides the module's function
Code review · Medium · §12.3, §12.4 Making your own module
When you moved the engagement rate function rate() into likekit.py, you changed it to round to one decimal place and to return 0.0 when the view count is 0. But when you run the code below, the second line prints 23.333333333333332. There is no error. Fix it so that it prints 25.0 and 23.3. Grading also runs the code with different posts and different contents of likekit.py.
Code to fix
from likekit import rate
def rate(likes, views):
return likes / views * 100
posts = [[30, 120], [7, 30]]
for likes, views in posts:
print(rate(likes, views))File likekit.py
def rate(likes, views):
if views == 0:
return 0.0
return round(likes / views * 100, 1)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.