Answer:
This program is written in Python
inputtime = input("HH:MM:SS AM/PM: ")
splittime = inputtime.split(":")
secondAM = splittime[2].split()
if secondAM[1] == "AM":
print(splittime[0]+":"+splittime[1]+":"+secondAM[0])
elif secondAM[1] == "PM":
HH = int(splittime[0])
HH = HH + 12
print(str(HH)+":"+splittime[1]+":"+secondAM[0])
Step-by-step explanation:
This line prompts user for input
inputtime = input("HH:MM:SS AM/PM: ")
This line splits the input string to HH, MM and "SS AM/PM"
splittime = inputtime.split(":")
This line splits "SS AM/PM" to SS and AM/PM
secondAM = splittime[2].split()
This line checks if time is AM
if secondAM[1] == "AM":
This line prints the equivalent time
print(splittime[0]+":"+splittime[1]+":"+secondAM[0])
Else;
elif secondAM[1] == "PM":
The equivalent 24 hour is calculated
HH = int(splittime[0]) + 12
This line prints the equivalent time
print(str(HH)+":"+splittime[1]+":"+secondAM[0])