Exercise 2 (Time Module)
#Create a python program capable of gretting you with Good Morning, Good Afternoon, and Good Evening. Your program should use time module to get the current hour.
#Solution 1
import time
t = time.strftime('%H: %M: %S')
timestamp = int(time. strftime('%H'))
minutes = int(time. strftime('%M'))
seconds = int(time. strftime('%S'))
print("Hours", "=", timestamp)
print("Minutes", "=", minutes)
print("Seconds", "=", seconds)
if timestamp >0 and timestamp <12:
print("Good Morning")
elif timestamp >=12 and timestamp <17:
print("Good Afternoon")
elif timestamp >=17 and timestamp <20:
print("Good Evening")
else:
print("Good Night")
# output =
# Hours = 21
# Minutes = 22
# Seconds = 38
# Good Night
Comments
Post a Comment