0
Codecoach[military time] problem
s=input().split() p=s[1] s=s[0].split(':') if(p=='PM' and int(s[0])==12): print('00'+':'+s[1]) elif(p=='PM'): print(str(int(s[0])+12)+':'+s[1]) else: print("%02d:%02d" %(int(s[0]),int(s[1]))) Share any other ways to do it
10 Respostas
+ 5
I did not test your code but I would say your output format is wrong.
Output: XX:XX
01:45 instead of 1:45.
+ 4
Geek it has already been asked, please use the searchbar next time
+ 3
Check this out!
https://code.sololearn.com/cy9T0LRzvJ9A/?ref=app
+ 2
i got this:
https://code.sololearn.com/cM3fL6gmXxy9/?ref=app
+ 1
Noob , technically speaking... 12:XX PM would mean the afternoon so the 24 hour time format of 12:XX would be correct. At one minute before midnight (11:59 PM) the time would be 23:59 and at the stroke of midnight (12:00 AM) the new day starts, so 24 hour time format would be 00:00.
In denoting military time (in USA) it is also correct to omit the colon and abbreviate hours as HRS.
Example: All below are valid notations of the same time.
âą 11:59 PM
âą 23:59
âą 2359 HRS
0
print("%02d:%02d" %(int(s[0]),int(s[1])))
is there any other way to do it?
0
time = str(input())
h = time[0:2]
c = time[2]
m = time[3:5]
t = time[6::]
if t == "AM":
print(f'{h}{c}{m}')
elif t == "PM":
print(f'{int(h)+12}{c}{m}')
0
time = input()
x = time.split(':')
pref = int(x[0])
for i in x[1]:
if i == 'P' and pref !=12:
pref +=12
elif i == 'A' and pref <11:
pref = str(pref).zfill(2)
elif i == 'A' and pref == 12:
pref = (f'00')
print(f'{pref}:{x[1][0:2]}')
0
here is mine, ithe code like of human-ish way, and sorry for bad variable
time = input().upper()
if time.endswith('AM'):
c = time.index('A')
print(time[:c])
if time.endswith('PM'):
a = time.index(':')
d = time.index('P')
b = str(abs(int(time[:a])+12))
print (b+time[a:d])
0
Try this :)
def hrstime24(x):
if x[-2:] == 'AM':
return x[:-2]
elif x[-2:] == 'PM':
return str(int(x[:2])+12)+x[2:5]
print(hrstime24(input()))