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)
1 ответ
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)