0% found this document useful (0 votes)
26 views1 page

Python Solution ' Def TimeConversio

The document contains Python code for a function called 'timeConversion' that converts time from 12-hour format to 24-hour format. It handles both AM and PM cases, adjusting the hour accordingly. The function returns the converted time as a formatted string.

Uploaded by

akanksha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Python Solution ' Def TimeConversio

The document contains Python code for a function called 'timeConversion' that converts time from 12-hour format to 24-hour format. It handles both AM and PM cases, adjusting the hour accordingly. The function returns the converted time as a formatted string.

Uploaded by

akanksha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

python solution ` def timeConversion(s): # Write your code here

HH,MM,SS=map(int,s[:-2].split(":"))

if 'AM' in s and HH==12: HH=0

elif 'PM' in s and HH<12: HH=HH+12

return((f"{HH:02}:{MM:02}:{SS:02}")) `

0|Add CommentPermalink

vivekkishore0600 2 months ago


python solution

def timeConversion(s): # Write your code here HH,MM,SS=map(int,s[:-2].split(":"))

if 'AM' in s and HH==12:


HH=0

elif 'PM' in s and HH<12:


HH=HH+12

return((f"{HH:02}:{MM:02}:{SS:02}"))
0|Add CommentPermalink

Thihamyng 2 months ago


Python

def timeConversion(s):
# Write your code here
am = s[-2:]
time_f = s[:-2].split(':')
if am=='AM':
if time_f[0]=='12':
time_f[0]='00'
else:
if time_f[0]!='12':
time_f[0]= str(12+int(time_f[0]))
return ':'.join(time_f)

------------------
-----------------------------------------
am = s[-2:]
time_f = s[:-2].split(':')
if am=='AM':
if time_f[0]=='12':
time_f[0]='00'
else:
if time_f[0]!='12':
time_f[0]= str(12+int(time_f[0]))
return ':'.join(time_f)

You might also like