Greetings Program in Python
Just enter your name and the program will greet you according to the time of the day.
Note: If you run this program on your computer, it will respond according to your system time. In case you run this program on any online platform, it may respond according to the server time on which that platform is hosted.
import time
name = input("Plz enter your name: ")
# timeNow = time.strftime("%H:%M:%S")
# print(timeNow)
hr = int(time.strftime("%H"))
# print(hr)
mints = int(time.strftime("%M"))
# print(mints)
secs = int(time.strftime("%S"))
# print(secs)
if hr in range(6, 12):
if mints in range(0, 60):
if secs in range(0, 60):
print("Good Morning", name)
elif hr in range(12, 14):
if mints in range(0, 60):
if secs in range(0, 60):
print("Good Noon", name)
elif hr in range(14, 17):
if mints in range(0, 60):
if secs in range(0, 60):
print("Good Afternoon", name)
elif hr in range(17, 20):
if mints in range(0, 60):
if secs in range(0, 60):
print("Good Evening", name)
elif hr in range(20, 25):
if mints in range(0, 60):
if secs in range(0, 60):
print("Good Night", name)
else:
print("Sleep tight!", name)
"""
Hints:
Good morning! -> 06:00:00 - 11:59:59
Good noon! -> 12:00:00 - 13:59:59
Good afternoon! -> 14:00:00 - 16:59:59
Good evening! -> 17:00:00 - 19:59:59
Good night! -> 20:00:00 - 05:59:59
"""
Comments
Post a Comment
Write something to CodeWithAbdur!