Python Python Basics (2015) Number Game App Even or Odd

Robert Femi
Robert Femi
689 Points

This one should be short and sweet. Challenge Task 1 of 1

Why isn't the code accepted if I put ("True") and ("False") but it's accepted if remove brackets and quotation marks? Spent a LONG time figuring that out and would like to learn why so at least it won't be a complete waste of time. Would appreciate if someone can explain that to me. Many thanks.
def even_odd(number):
    if number % 2 == 0:
        return ("True")
        return ("False")

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,857 Points

Hi Robert,

Strictly, the problem is just with the quotation marks, not with the parens.

return (True)

will pass but

return ("True")

will not. This is because True and "True" are completely different data types. True is a boolean (a data type that can only ever be True or False, and Python can understand semantically what true and false mean) and "True" is a string (and Python doesn't generally have any way to understand what is semantically in a string, just that it is a sequence of characters).

As for the parentheses, they are completely redundant and should be removed.