We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deftimeConversion(s):# get the time indicatortime_indicator=s[-2:]# extract minutes and seconds because they stay fixed# format (e.g.): ":00:00"mins_secs=s[2:-2]# extract hour (the thing to alter if necessary)hour=s[:2]# handle edge cases (i.e. 12)ifhour=="12":iftime_indicator=="AM":military_time="00"+mins_secselse:military_time=hour+mins_secs# all the other hourselse:iftime_indicator=="AM":military_time=hour+mins_secselse:# add leading zero if not already two digitsadjusted_hour="{:0>2}".format(str(int(hour) + 12))military_time=adjusted_hour+mins_secsreturnmilitary_time
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →