I was doing a question on code coach, but it's not working well. | Sololearn: Learn to code for FREE!
0

I was doing a question on code coach, but it's not working well.

To convert 12 hour format to 24 hour format. No errors but also not correct output😶🙄. Need a solution real quick, it's kind of demotivating https://code.sololearn.com/cM0i9IZ9308H/?ref=app

8th Jan 2020, 5:35 AM
Karan Sharma
Karan Sharma - avatar
6 Answers
+ 1
the issue probably lies in how they want the output. In any case with the hour less than 10 it needs a 0 in front. aka: 1:30 wouldn’t be accepted but 01:30 would. Hope this helps!
8th Jan 2020, 5:41 AM
Pie
Pie - avatar
+ 1
Karan Sharma Your issue isnt that the if statment isnt working. It actually is. Your real issue is that you arent properly parsing the time. You want 11 00 PM to turn to 23:00 but currently you check the third character to see if it is pm or not. In an example '11 00 PM' the third character is a space. If you input 11PM hoverever your program actually does work and returns 23:00. It just doesn’t accomidate for the other 59 minutes you might want in a clock lol. If you are comfortable with splitting a string up into parts then i would suggest seprating the input by spaces. That way you can have the hour, minute, and am/pm seperate from each other.
8th Jan 2020, 6:59 AM
Pie
Pie - avatar
+ 1
Coder Kitten yes, already did that and Ipang helped me in that,#great_guy 🖤
8th Jan 2020, 7:38 AM
Karan Sharma
Karan Sharma - avatar
0
Hay Pie , I've corrected that what you mentioned above, but There's one more problem; The if statement is not working, maybe just try to input 11 00 PM and it gives output as 11 00 instead of 23 00. That's kinda weird i guess...
8th Jan 2020, 6:05 AM
Karan Sharma
Karan Sharma - avatar
0
Pie cod coach condition for input is 11 00 PM, with spaces so now, I how can you figure out that?
8th Jan 2020, 7:04 AM
Karan Sharma
Karan Sharma - avatar
0
Yes sure Pie helped too, and that was important point And code is now working fine , https://code.sololearn.com/cM0i9IZ9308H/?ref=app
8th Jan 2020, 7:48 AM
Karan Sharma
Karan Sharma - avatar