0

Why does the third and fifth error?

My code : q = input() lenq = len(q) sta = q.split (" ") if sta[1] == "AM": j = 0 else: j = 1 if j == 1: tim = sta[0].split (":") tim[0] = int(tim[0]) tim[0] += 12 tim[0] = str(tim[0]) if tim[0] == 24: tim[0] = "00" if int(tim[0]) < 10: tim[0] = "0"+tim[0] res = tim[0]+":"+tim[1] print (res) else: print (sta[0]) Coach code link : https://sololearn.com/coach/70/?ref=app

28th Jan 2021, 6:39 PM
Sadra Shakouri
Sadra Shakouri - avatar
1 ответ
+ 3
Your format for AM times is not correct. 9:00AM has to be printed as 09:00AM. You might also consider cleaning the code up a bit. Do you need the i and j values? They are not used for anything else other that selecting the right path in the second if statement. Why not just put the conversion code in the first one? In the PM path, when you add 12 to the hour, do you need to check for values < 10? Anything greater or equal 12, if you add 12 to it, it will always be greater than 10. The only time this will be true is when you have value 24, in which can, you end up with '000' as hour.
29th Jan 2021, 12:08 AM
Mateusz Malenta
Mateusz Malenta - avatar