#Individual coding task 2 solution
#get the current time and greet based on the time
#get the time in the correct HH:MM format
currenttime = input("Enter the current time in HH:MM 24 hour format: ")
#split the time into hours and minutes
splittime = currenttime.split(':')
#convert the minutes and hours to numbers
splittime[0] = int(splittime[0])
splittime[1] = int(splittime[1])
#use the hours(the first part of splittime) to work out the greeting
if splittime[0]<12: #below 12 it is before noon
print("Good Morning")
elif splittime[0]>=12 and splittime[0]<16: #above 12 and below 16
print("Good Afternoon")
elif splittime[0]>=16 and splittime[0]<19: #above 16 and below 19
print("Good Evening")
else: #must be before midnight
print("Good Night")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter