-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime-conversion.py
More file actions
38 lines (28 loc) · 970 Bytes
/
time-conversion.py
File metadata and controls
38 lines (28 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# https://www.hackerrank.com/challenges/one-week-preparation-kit-time-conversion/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=preparation-kits&playlist_slugs%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D=one-week-day-one&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'timeConversion' function below.
#
# The function is expected to return a STRING.
# The function accepts STRING s as parameter.
#
def timeConversion(s):
hour = s[:2]
if s[-2:] == "AM" and hour == '12':
hour = "00"
if s[-2:] == "PM" and hour == '12':
hour = "12"
if s[-2:] == "PM" and hour != '12':
hour = str(int(hour) + 12)
return hour + s[2:-2]
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = timeConversion(s)
fptr.write(result + '\n')
fptr.close()