| 4 | |
| 5 | |
| 6 | def convert_time(input_str): |
| 7 | # Checking if last two elements of time |
| 8 | # is AM and first two elements are 12 |
| 9 | if input_str[-2:] == "AM" and input_str[:2] == "12": |
| 10 | return "00" + input_str[2:-2] |
| 11 | |
| 12 | # remove the AM |
| 13 | elif input_str[-2:] == "AM": |
| 14 | return input_str[:-2] |
| 15 | |
| 16 | # Checking if last two elements of time |
| 17 | # is PM and first two elements are 12 |
| 18 | elif input_str[-2:] == "PM" and input_str[:2] == "12": |
| 19 | return input_str[:-2] |
| 20 | |
| 21 | else: |
| 22 | # add 12 to hours and remove PM |
| 23 | return str(int(input_str[:2]) + 12) + input_str[2:8] |
| 24 | |
| 25 | |
| 26 | if __name__ == "__main__": |