+ 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)

1st Jan 2020, 8:38 AM
Little Light 🕯️
Little Light 🕯️ - avatar
13 Antworten
+ 2
I also struggled with that challenge. Keep going buddy
1st Jan 2020, 9:39 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
1st Jan 2020, 9:23 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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..
1st Jan 2020, 9:37 AM
Little Light 🕯️
Little Light 🕯️ - avatar
+ 1
Happy to hear you managed it eventually 😊 Rik Wittkopp
1st Jan 2020, 9:40 AM
Little Light 🕯️
Little Light 🕯️ - avatar
+ 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
1st Jan 2020, 9:49 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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...
1st Jan 2020, 10:00 AM
Little Light 🕯️
Little Light 🕯️ - avatar
+ 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!
1st Jan 2020, 10:07 AM
Little Light 🕯️
Little Light 🕯️ - avatar
+ 1
Col ha cavod lekha. Best feeling when you get the answer. Well done & congrats
1st Jan 2020, 10:09 AM
Rik Wittkopp
Rik Wittkopp - avatar
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.
1st Jan 2020, 9:06 AM
Little Light 🕯️
Little Light 🕯️ - avatar
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
1st Jan 2020, 9:38 AM
Little Light 🕯️
Little Light 🕯️ - avatar
0
🤔
1st Jan 2020, 10:02 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
The code that you submit still does not work in case 4
2nd Jan 2020, 1:03 PM
Zetra_coder
Zetra_coder - avatar
0
It did work for me, are you sure you took the correct version :)?
2nd Jan 2020, 1:43 PM
Little Light 🕯️
Little Light 🕯️ - avatar