From dc5a0a441d1378c0a43b566765059bea706e578b Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Tue, 18 Oct 2022 17:33:15 +0300 Subject: [PATCH] Add Lesson 1 Task 3 --- Lesson_1/task3.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Lesson_1/task3.py diff --git a/Lesson_1/task3.py b/Lesson_1/task3.py new file mode 100644 index 0000000..7526f34 --- /dev/null +++ b/Lesson_1/task3.py @@ -0,0 +1,27 @@ +# Lesson 1 Task 3: calculate how much time passed since Unix epoch +# Author: Stanislav Mykhailenko +# License: Unlicense + +# Return codes: +# 0 - OK +# 1 - Invalid Unix timestamp entered + +import sys + +try: + timestamp = int(input("Enter Unix timestamp: ")) +except ValueError: + print("Invalid Unix timestamp entered.") + sys.exit(1) + +# duration in seconds +day = 86400 # 24 * hour +hour = 3600 # 60 * minute +minute = 60 + +days = int(timestamp / day) +hours = int(int(timestamp % day) / hour) +minutes = int(int(int(timestamp % day) % hour) / minute) +seconds = int(int(timestamp % day) % hour) % minute + +print(str(days) + ":" + str(hours) + ":" + str(minutes) + ":" + str(seconds))