How to make a function that take one parameter and boolean in Python
Question:
How to make a function hours that receives seconds from 00:00 (midnight) and a boolean parameter that is True to return a 24h-based hour, and False for a 12h-based hour, and returns hours (as a 12h or 24h clock depending on the second parameter)
def hours(seconds : int, type : bool) -> int: return seconds // 3600
Answers:
Couldn’t you just return (seconds // 3600) % 12
if the type is for 12h, otherwise just return (seconds // 3600)
?
def hours(seconds: int, type: bool) -> int:
hours = seconds // 3600
if type:
return hours
return hours % 12
The question is worded kind of strangely, but this maybe useful for you?
def hours(seconds):
if seconds > 1259:
return False
else:
return True
seconds
is parameter to enter for function. Function will return False
boolean value if entered argument is higher than 1259
How to make a function hours that receives seconds from 00:00 (midnight) and a boolean parameter that is True to return a 24h-based hour, and False for a 12h-based hour, and returns hours (as a 12h or 24h clock depending on the second parameter)
def hours(seconds : int, type : bool) -> int: return seconds // 3600
Couldn’t you just return (seconds // 3600) % 12
if the type is for 12h, otherwise just return (seconds // 3600)
?
def hours(seconds: int, type: bool) -> int:
hours = seconds // 3600
if type:
return hours
return hours % 12
The question is worded kind of strangely, but this maybe useful for you?
def hours(seconds):
if seconds > 1259:
return False
else:
return True
seconds
is parameter to enter for function. Function will return False
boolean value if entered argument is higher than 1259