why this code of military time in code coach is not working properly it is python | Sololearn: Learn to code for FREE!
0

why this code of military time in code coach is not working properly it is python

import re x = str(input("")) y =(x [:2]) a = "A" p = "P" v = int(y) for c in x : if c == p and v == 12 : print("12:00") elif c == p : v = str(v+12) x = re.sub( y, v, x) x = re.sub("PM","",x) for c in x : if c == a and v == 12 : print("00:00") elif c == a: v = str(v) x = re.sub( y, v, x) x =re.sub("AM" , "",x) print(x)

26th Aug 2020, 10:33 AM
ItzMk
ItzMk - avatar
1 Answer
0
Here is your exact code with the spaces removed: import re x = str(input("")) y =(x[:2]) a = "A" p = "P" v = int(y) for c in x:   if c == p and v == 12:     print("12:00")   elif c == p:       v = str(v+12)       x = re.sub(y, v, x)       x = re.sub("PM","",x) for c in x:    if c == a and v == 12:      print("00:00")    elif c == a:      v = str(v)      x = re.sub(y, v, x)      x =re.sub("AM" , "",x) print(x) Your programme is waiting for a time to be entered. Try: 11:34 PM > 23:34 So far so good. but if I try: 1:15 PM I get an error. Your y variable is trying to make an int out of ‘1:’ so this is where you need to change you code (line 3)
27th Aug 2020, 5:41 PM
Colin Frame
Colin Frame - avatar