Converting time from AM/PM format to military time in Python
<p>Without using any libraries, I'm trying to solve the Hackerrank problem "<a href="https://www.hackerrank.com/challenges/time-conversion?h_r=next-challenge&amp;h_v=zen" rel="nofollow">Time Conversion</a>", the problem statement of which is copied below.</p>

<p><a href="http://i.stack.imgur.com/YRr6p.png" rel="nofollow"><img src="http://i.stack.imgur.com/YRr6p.png" alt="enter image description here"></a></p>

<p>I came up with the following:</p>

<pre><code>time = raw_input().strip()

meridian = time[-2:]        # "AM" or "PM"
time_without_meridian = time[:-2]
hour = int(time[:2])

if meridian == "AM":
    hour = (hour+1) % 12 - 1
    print ("%02d" % hour) + time_without_meridian[2:]
elif meridian == "PM":
    hour += 12
    print str(hour) + time_without_meridian[2:]
</code></pre>

<p>However, this fails on one test case:</p>

<p><a href="http://i.stack.imgur.com/yQLb9.png" rel="nofollow"><img src="http://i.stack.imgur.com/yQLb9.png" alt="enter image description here"></a></p>

<p>Since the test cases are hidden to the user, however, I'm struggling to see where the problem is occurring. "12:00:00AM" is correctly converted to "00:00:00", and "01:00:00AM" to "01:00:00" (with the padded zero). What could be wrong with this implementation?</p>

<p>It's even simpler than how you have it.</p>

<pre><code>hour = int(time[:2])
meridian = time[8:]
if (hour == 12):
    hour = 0
if (meridian == 'PM'):
    hour += 12
print("%02d" % hour + time[2:8])
</code></pre>

python