0

what is wrong with this military time code.

i write this code using python and i am a beginner. please see the military time problem which is given by sololearn, i created this code. anyone please help me. code : x = int(input("Enter The Time: ")) y = input("enter AM or PM: ") if x >= 1 and y == AM: print(x) elif x >=1 and y == PM: print(x+12) else: print("please enter the right time!")

11th Jul 2020, 2:10 PM
Mr. 12
Mr. 12 - avatar
8 Respostas
+ 3
Ex: Input sample : 07:22 PM You can read this into a single variable as a string. You have to convert this to required answer, that is 19:22 Varies ways you can. In your code, it can't convert to int directly... Just take as input(), no text inside. If you extract 'AM' or 'PM' to y then, stil it is string so compare like y=='AM' or y=='PM'.
11th Jul 2020, 2:31 PM
Jayakrishna 🇮🇳
+ 2
Hint: AM/PM is the name of a object, not a String
11th Jul 2020, 2:24 PM
Esch
Esch - avatar
+ 1
Thanks Esch that's another problem. Yes Mr. 12 , the input is provided within a single line as a single string. You have to parse it.
11th Jul 2020, 2:26 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Single line, single string input: "12:34 am" e.g.
11th Jul 2020, 2:27 PM
Sandra Meyer
Sandra Meyer - avatar
0
The code coach will provide the input within a single line. You may not output an additional message when getting the output, because it will be printed and clutter your output. And you'll have to handle the 24:00 problem.
11th Jul 2020, 2:20 PM
Sandra Meyer
Sandra Meyer - avatar
0
Sandra Meyer are you saying that i have to use only one input?
11th Jul 2020, 2:21 PM
Mr. 12
Mr. 12 - avatar
0
You want to convert the time from a 12 hour clock to a 24 hour clock. If you are given the time on a 12 hour clock, you should output the time as it would appear on a 24 hour clock. Task: Determine if the time you are given is AM or PM, then convert that value to the way that it would appear on a 24 hour clock. Input Format: A string that includes the time, then a space and the indicator for AM or PM. Output Format: A string that includes the time in a 24 hour format (XX:XX) Sample Input: 1:15 PM Sample Output: 13:15
11th Jul 2020, 2:26 PM
Mr. 12
Mr. 12 - avatar
0
Esch @esci i didn't understand bro. please explain me
11th Jul 2020, 2:26 PM
Mr. 12
Mr. 12 - avatar