(Jul-02-2017, 10:04 PM)ichabod801 Wrote: It seems to be calculating correctly. If the only problem is getting the hours and minutes into a string, you can calculate that from the seconds attribute of the timedelta object:
hours = countdown.seconds // 3600 minutes = (countdown.seconds // 60) % 60 print('The market opens in {} hours and {} minutes.'.format(hours, minutes))
Alternate way.
from collections import namedtuple def to_hms(seconds): st_time = namedtuple('time', 'hours minutes seconds') minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) return st_time(hours, minutes, seconds) countdown = to_hms(3660) print(f"Sydney opens in {countdown.hours} hours and {countdown.minutes} minutes")
Output:Sydney opens in 1 hours and 1 minutes
Btw: namedtuple is underused. But the interesting part is divmod.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!