Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
using lamda (with some explanations) solution in Clear category for Just Fizz! by mu_py
checkio = lambda num: str(num) if num % 3 else 'Fizz'
# "num % 3" gives the remainder of the devision by 3
# the expression is "True" (<>0; here: 1 or 2), when num is NOT devideable by 3
# if num is devideable by 3, "num % 3" yields "0", which is interpreted as "False"
# Yes, in this example the logic of True/False is kinda non-intuitive
print("Example:")
print(checkio(3))
# These "asserts" are used for self-checking
assert checkio(15) == "Fizz"
assert checkio(6) == "Fizz"
assert checkio(10) == "10"
assert checkio(7) == "7"
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 20, 2022
Comments: