+ 1

Problem with split() method

I need to split input text (12:00 AM). Here is my code: a = str(input().split()) #12:00 for i in a: c = i[0] print(c, end = "") #['12:00', 'AM'] But I want to get this ( ['12:00' ]) please help me and sorry for my bad English.

2nd Apr 2020, 4:40 PM
Андрей Пермяков
Андрей Пермяков - avatar
27 odpowiedzi
+ 5
You could just keep it simple https://code.sololearn.com/cTjMmDD1Ox1d
4th Apr 2020, 3:43 PM
David Ashton
David Ashton - avatar
+ 3
#you can get an idea from this code otherwise ask time=input() if time=='12:00' or time=='12:00 AM': print("00:00") else: split=time.split() mist=split[1] itsob=split[0] its8=itsob[0:-3] nevermind=itsob[3::] itsmin2=itsob[3::] itsmin=itsob[2::] another=itsob[0:-3] if mist=="PM": if int(its8)<=9: newval=int(its8)+12 print(str(newval)+":"+str(itsmin)) elif int(its8)>9: newval2=int(another)+12 print(str(newval2)+":"+str(itsmin2)) elif mist=="AM": if int(its8)<=9: print("0"+str(another)+":"+str(itsmin)) elif int(its8)>9: print(str(another)+":"+str(nevermind)) #split0 is 08:45
2nd Apr 2020, 5:31 PM
Tricker
+ 2
a = str(input().split()[0]) for i in a: c = i[0] print(c, end = "") #['12:00', 'AM'] In line 1 i have indexed the list's first part.
2nd Apr 2020, 5:01 PM
Tricker
+ 1
Aaah. I got it. It happened because of "str". Man thank you very much!
2nd Apr 2020, 4:59 PM
Андрей Пермяков
Андрей Пермяков - avatar
+ 1
Тем более можно и так с тобой
2nd Apr 2020, 4:59 PM
Андрей Пермяков
Андрей Пермяков - avatar
+ 1
Спасибо большое!
2nd Apr 2020, 5:00 PM
Андрей Пермяков
Андрей Пермяков - avatar
+ 1
Thank you again!
2nd Apr 2020, 5:30 PM
Андрей Пермяков
Андрей Пермяков - avatar
+ 1
Hello
3rd Apr 2020, 8:15 PM
Belazerava Viktoria
Belazerava Viktoria - avatar
+ 1
It's supposed to be: a = input().split() #["12:00","AM"] then, print(a[0]) #"12:00"
4th Apr 2020, 6:47 AM
David Emmanuel
David Emmanuel - avatar
+ 1
12×12=9 23×23=16 34×34=?
4th Apr 2020, 1:14 PM
Belazerava Viktoria
Belazerava Viktoria - avatar
0
Another one question, I have the mission: a = input().split() b = a[0] r = a[1] c = b.split(":") d = c[0] f = c[1] if r == "AM": print(d + ":" + f) else: g = str(int(d) + 12) print( g + ":" + f ) #time converter
2nd Apr 2020, 5:22 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
I hope you'll understand
2nd Apr 2020, 5:22 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
So, 3 tests out of 5 I passed and I do not know why the rest are wrong
2nd Apr 2020, 5:26 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
For example I have 1:00 PM and my program needs to convert this to 13:00, my program can do it but tests think differently
2nd Apr 2020, 5:28 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Mission called "Military time"
2nd Apr 2020, 5:30 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Indeed
2nd Apr 2020, 5:30 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Omao
2nd Apr 2020, 5:31 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Okey
2nd Apr 2020, 5:31 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
I'll check it
2nd Apr 2020, 5:32 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
Thanks
2nd Apr 2020, 5:33 PM
Андрей Пермяков
Андрей Пермяков - avatar