Skip to content Skip to sidebar Skip to footer

Python Function Prints None

I have the following exercise: The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday

Solution 1:

Functions in python return None unless explicitly instructed to do otherwise.

In your function above, you don't take into account the case in which weekday is True. The interpreter reaches the end of the function without reading a return statement (since the condition predecing yours evaluates to False), and returns None.

Edit:

defsleep_in(weekday, vacation):
    return (not weekday or vacation)

There you go =)

Post a Comment for "Python Function Prints None"