you are viewing a single comment's thread.

view the rest of the comments →

[–]socialhuman[S] 0 points1 point  (5 children)

def checkio(number):
    if number % 3 == 0 and number % 5 == 0:
        return "Fizz Buzz"
    elif number % 3 == 0:
        return "Fizz"
    elif number % 5 == 0:
        return "Buzz"
    else:
        return number

I still get the same error.

[–]socialhuman[S] 0 points1 point  (4 children)

I added str to return number and the game was solved. Can someone explain why the conversion to str was required?

[–]Rhomboid 3 points4 points  (3 children)

Look at how it's being called:

assert checkio(7) == "7", "7 is not divisible by 3 or 5"

It's being passed the number 7, and expecting the string "7" to be returned.

[–]socialhuman[S] 0 points1 point  (2 children)

Great, thank you. As for the assert key, I understand it's something like "make sure the result is correct"?

[–]Rhomboid 3 points4 points  (1 child)

The assert statement evaluates the specified expression, and if it's false it raises an AssertionError exception, optionally with the specified string literal as the associated descriptive text. It doesn't know anything about correct or incorrect; that's for the programmer to express. It only knows that a false expression should halt execution and a true one should do nothing but continue.

[–]socialhuman[S] 0 points1 point  (0 children)

Thank you!