laflame
Aryan Shahane, Sugamay Gakhar, Jishnu Ganisetti
def greeting(time): try: time_parts = time.split() if len(time_parts) != 2: print("Invalid time format. Please include AM or PM.") return
hour, minute = map(int, time_parts[0].split(':'))
period = time_parts[1].upper()
if period not in ['AM', 'PM']:
print("Invalid time format. Please include AM or PM.")
return
if period == 'AM':
if 0 <= hour < 12:
print("Good morning!")
else:
print("Invalid time format for AM period.")
else: # period == 'PM'
if hour == 12:
print("Good afternoon!")
elif 12 <= hour < 18:
print("Good afternoon!")
else:
print("Good evening!")
except ValueError: print("Invalid time format. Please enter time in HH:MM AM/PM format.")
time_input = input("Enter the time in HH:MM AM/PM format: ") greeting(time_input)
Log in or sign up for Devpost to join the conversation.