An engagement rate function that only prints

Code review · Medium · §8.2, §8.7 [Pair coding with AI] Asking for functions

You asked an AI for a function that returns the engagement rate (%), and this is the code you got. It runs without an error, but r gets None. Fix it so that it returns the engagement rate, and returns 0.0 when the view count is 0.

Code to fix

def get_rate(likes, views):
    print(likes / views * 100)

r = get_rate(30, 120)
print(r)

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.