I'm going through a basic python exercise, stumbled upon this query.
Given a non-negative number "num", return True if num is within 2 of a multiple of 10.
Given a non-negative number "num", return True if num is within 2 of a multiple of 10.
Here's the my solution:
def near_ten(num):
return (num % 10) in range(8, 10) or (num % 10) in range(0, 3)
It shows "All Correct", but I'm feeling like my code is bit digressive as I have hard-coded the "numbers within 2 of a multiple of 10".
Can one please review this line if its the right approach?