May-31-2018, 04:18 AM
The problem:
We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return true if we are in trouble.
My code:
We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return true if we are in trouble.
My code:
def parrot_trouble(talking, hour): if hour<7 or hour>20: return talking else: return FalseTheir solution:
def parrot_trouble(talking, hour): return (talking and (hour < 7 or hour > 20))How does the simplified version work? I don't understand how the "and" works in that final return statement.