Last active
May 23, 2021 09:53
-
-
Save minte9/6e4330d6197c348f8af6e1fe70571a68 to your computer and use it in GitHub Desktop.
Python / Language / Conditional - https://www.minte9.com/python/language-conditional-1251
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a function convert() that returns | |
# days, hours, minutes, seconds since UTC | |
# The time module provides a function, also named time, | |
# that returns the current GMT in “the epoch” | |
import time | |
today = time.time() | |
# SOLUTION | |
def convert(t): | |
# SOLUTION | |
days = int(t) // (3600 * 24) | |
r = int(t) % (3600 * 24) # remainder | |
hours = r // 3600; r = r % 3600 | |
minutes = r // 60; r = r % 60 | |
seconds = r | |
return ( | |
str(days) + " days " + \ | |
str(hours) + " hours " + \ | |
str(minutes) + " minutes " + \ | |
str(seconds) + " seconds " | |
) | |
print(convert(today)) | |
# 18769 days 20 hours 16 minutes 9 seconds | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment