In: Computer Science
Complete the Python function called 'greetings(time)' that accepts a time in "HH:MM" format as a string. The function should return a greeting message based on the hour given in the time object as follow:
If the time is before noon: 'Good Morning.', if it is in the afternoon: 'Good Day.'
Please use the following template for your python script to
define the greetings() function and name it as
mt_q3.py. Replace the place holder
[seneca_id] with your Seneca email user
name. You are allowed to use any built-in functions in the
greetings() function.
#!/usr/bin/env python3
# program: mt_q3.py
# author_id: [seneca_id]
def greetings(time):
    greeting_message = ''
    # put code below to set the appropriate greeting
message based on the time of the day
    # before noon: Good Morning.
    # after noon: Good Day.
    return greeting_message
if __name__ == '__main__':
    time = input('What is the time in HH:MM?
')
    print('Hello,',greetings(time))
Note: In the output of the following sample run, bold face
characters in red color are typed in by user on
the keyboard.
Sample run of the mt_q3.py script:
[rchan@centos7 mt_test]$ python3 mt_q3.py
What is the time in HH:MM? 00:01
Hello, Good Morning.
[rchan@centos7 mt_test]$ python3 mt_q3.py
What is the time in HH:MM? 11:59
Hello, Good Morning.
[rchan@centos7 mt_test]$ python3 mt_q3.py
What is the time in HH:MM? 12:00
Hello, Good Day.
[rchan@centos7 mt_test]$ python3 mt_q3.py
What is the time in HH:MM? 23:59
Hello, Good Day.
Please find below code and don't forget to give a Like.
Please refer below screenshot for indentation and output:
code:
def greetings(time):
    if(len(time)==1 or len(time)==2):
        return "Not valid timings"
    greeting_message = ''
    index1=time.index(":") #getting the index value for getting hours
    last=len(time)
    mins=int(time[index1+1:last]) #for mins validation 0 to 59 only
    hours=int(time[0:index1])# getting hours from 1st letter to till :
    #condition for good morning
    if((hours>=00 and hours<=11) and(mins>=0 and mins<=59)):
        greeting_message+="Good Morning."
    #condition for good day
    elif((hours>11 and hours<24)and(mins>=0 and mins<=59)):
        greeting_message+="Good Day."
    #if time is not valid
    else:
        greeting_message+="Not valid timings"
    return greeting_message
if __name__ == '__main__':
    time = input('What is the time in HH:MM? ')
    print('Hello,',greetings(time))
Output:


