Answer:
hour = float(input("Enter hour:"))
minute = float(input("Enter minute:"))
second = float(input("Enter second:"))
am_pm = input ("Enter AM or PM:")
if am_pm == "AM":
if hour == 12:
hour = 0
seconds_since_midnight = ((3600 * hour) +(minute *60) + second)
elif am_pm == "PM":
seconds_since_midnight = ((3600 * (hour+12)) +(minute *60) + second)
print("Seconds since midnight:", int(seconds_since_midnight))
Explanation:
The point here is when PM is chosen, you need to add 12 to the hour. I added elif part to satisfy this. Moreover, since the output is in integer format, you may need to apply type casting for seconds_since_midnight variable.