Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f246899

Browse files
Add files via upload
1 parent 4b95c98 commit f246899

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

‎Time Conversion.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/python3
2+
3+
import os
4+
import sys
5+
6+
#
7+
# Complete the timeConversion function below.
8+
#
9+
def timeConversion(s):
10+
11+
received_date = s.split(':')
12+
13+
time = received_date[2]
14+
15+
if(time[2:] == "PM"):
16+
if(received_date[0] == "12"):
17+
received_date[0] = str(int(received_date[0]))
18+
else:
19+
received_date[0] = str(int(received_date[0]) + 12)
20+
21+
if(time[2:] == "AM" and received_date[0] == "12"):
22+
received_date[0] = "00"
23+
24+
25+
new_date = ':'.join(received_date)
26+
27+
return new_date[:-2]
28+
29+
if __name__ == '__main__':
30+
f = open(os.environ['OUTPUT_PATH'], 'w')
31+
32+
s = input()
33+
34+
result = timeConversion(s)
35+
36+
f.write(result + '\n')
37+
38+
f.close()
39+
40+
41+
42+
43+
44+
45+
46+
# Given a time in -hour AM/PM format, convert it to military (24-hour) time.
47+
48+
# Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.
49+
50+
# Function Description
51+
52+
# Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.
53+
54+
# timeConversion has the following parameter(s):
55+
56+
# s: a string representing time in hour format
57+
# Input Format
58+
59+
# A single string containing a time in -hour clock format (i.e.: or ), where and .
60+
61+
# Constraints
62+
63+
# All input times are valid
64+
# Output Format
65+
66+
# Convert and print the given time in -hour format, where .
67+
68+
# Sample Input 0
69+
70+
# 07:05:45PM
71+
# Sample Output 0
72+
73+
# 19:05:45

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /