Nov-08-2020, 01:44 AM
i do apologize i was messing around with finding different ways to do different things just exploring and learning. i was messing around having fun with time conversion.
this is what i came up with im sure there is a better way but i was asking if its possible to avoid all the if statements
this is what i came up with im sure there is a better way but i was asking if its possible to avoid all the if statements
def conversion(number, time, hms): if time == "minute": if hms == "second": minute_ = number * 60 elif hms == "minute": minute_ = number * 1 else: return return minute_ elif time == "hour": if hms == "second": hr = number * 3600 # 3600 seconds in an hour elif hms == "minute": hr = number * 60 elif hms == "hour": hr = number * 1 else: return return hr else: return # print(hour(1, h="second")) number = 1 # one hour time = "hour" # time in hms = "second" # seconds in a hour conver = conversion(number, time, hms) print(f"there are {conver} {hms}(s) in a {time}(s)")