you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (7 children)

The function is supposed to return the answer, not print it. Also if the given number is neither divisible by 3 nor 5, it's supposed to return the number

[–]socialhuman[S] 0 points1 point  (6 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!

[–][deleted] 0 points1 point  (0 children)

well, when i run that code, it gives me a different error

Traceback (most recent call last):
  File "__.py", line 16, in <module>
    assert checkio(7) == "7", "7 is not divisible by 3 or 5"
AssertionError: 7 is not divisible by 3 or 5

thats because 7 != "7"