Below is my code , totally C type programmer, no excellent skills.
import sys
#time = input().strip()
time = "00:05:45PM"
"""
I don't know this issue.
12:24:35AM -> 0:24:35
12:24:35PM -> 12:24:35
"""
print(time)
if time.find("AM") >= 0:
time = time.strip("AM")
if time == "12:00:00":
time = "00:00:00"
time = time.split(':')
hh = int(time[0])
mm = int(time[1])
ss = int(time[2])
if hh == 12 and (mm > 0 or ss > 0):
hh = 0
#print(time)
print("%02d:%02d:%02d" % (hh, mm, ss))
else:
time = time.strip("PM")
time = time.split(':')
hh = int(time[0])
mm = int(time[1])
ss = int(time[2])
#print (time[0])
#print (time[1])
#print (time[2])
if hh != 12:
hh = hh + 12
print("%02d:%02d:%02d" % (hh, mm, ss))
This is done by someone expert.
We’re in different level.
You find the Python type grammer.
string operation, list convert, map usage, and join, lambda.
ins = input().strip()
is_pm = ins[-2:].lower() == 'pm'
time_list = list(map(int, ins[:-2].split(':')))
if is_pm and time_list[0] < 12:
time_list[0] += 12
if not is_pm and time_list[0] == 12:
time_list[0] = 0
print(':'.join(map(lambda x: str(x).rjust(2, '0'), time_list)))