+ 1
Help with code for military time
I created this code, it doesn't work and I can't tell why... time = input() time2 = time.split() digits = list(time2[0]) two = digits[0]+digits[1] one = digits[0] stat = digits[-3]+digits[-2]+digits[-1] two2 = str(int(two)+12) one2 = str(int(one)+12) if time2[1]=='PM': if two.isdigit: print (two2+stat) else: print (one2+ stat) else: if two.isdigit(): print(two+stat) else: print('0'+one+stat)
13 Answers
+ 2
I also struggled with that challenge. Keep going buddy
+ 1
2 problems I found which I believe is affecting your code.
1/ 2:15 AM causes a problem.
I believe it is because output must be XX:XX.
2/ 12:01 AM produces 12:01.
Output should be 00:01
I hope this helps
+ 1
Thank you very much Rik Wittkopp, the second point you've mentioned might have been an issue, I think I took care of the first one, but even after adjusting it to print 00 it still fails one out of five tests..
+ 1
Happy to hear you managed it eventually 😊 Rik Wittkopp
+ 1
Hi Ohr Michaeli I notice whenever a single digit for hour is input, your code generates a fault.
IE: 2:30 AM, 4:15 PM
That's after I ran your update.
tamshikh habib
+ 1
Well done for your Hebrew Rik Wittkopp !
It seems it's only a problem with PM time, I understand the problem but it should have been fixed by my code, when it's only one digit the two variable can't convert into an integer thus creating the bug but I put it under a condition that was meant to prevent it so I don't understand why the if isn't doing his job...
+ 1
Rik Wittkopp found it! I forgot to put () after the isdigit and that's why the if wasn't working...it's 100% now, hearty thank you for your help!
+ 1
Col ha cavod lekha.
Best feeling when you get the answer.
Well done & congrats
0
I've found one problem with calculating of : as an integer so I moved it into the condition and now it's only failing in one test.
0
time = input()
time2 = time.split()
digits = list(time2[0])
two = digits[0]+digits[1]
one = digits[0]
stat = digits[-3]+digits[-2]+digits[-1]
one2 = str(int(one)+12)
if time2[1]=='PM':
if two.isdigit:
if '12' in two:
print ('12'+stat)
else:
two2 = str(int(two)+12)
print (two2+stat)
else:
print (one2+ stat)
else:
if two.isdigit():
if two=='12':
print ('00'+stat)
else:
print(two+stat)
else:
print('0'+one+stat)
That's my updated version Rik Wittkopp
0
🤔
0
The code that you submit still does not work in case 4
0
It did work for me, are you sure you took the correct version :)?