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.
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):
# Write your code here
period=s[-2:]
hours,minutes,seconds=map(int,s[:-2].split(':'))
if period=='AM' and hours==12:
hours=0
elif period=='PM' and hours !=12:
hours+=12
return f"{hours:02}:{minutes:02}:{seconds:02}"
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = timeConversion(s)
fptr.write(result + '\n')
fptr.close()
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 →
!/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): # Write your code here period=s[-2:] hours,minutes,seconds=map(int,s[:-2].split(':')) if period=='AM' and hours==12: hours=0 elif period=='PM' and hours !=12: hours+=12 return f"{hours:02}:{minutes:02}:{seconds:02}"
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')