+ 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.
27 Answers
+ 5
You could just keep it simple
https://code.sololearn.com/cTjMmDD1Ox1d
+ 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
+ 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.
+ 1
Aaah. I got it. It happened because of "str". Man thank you very much!
+ 1
Тем более можно и так с тобой
+ 1
Спасибо большое!
+ 1
Thank you again!
+ 1
Hello
+ 1
It's supposed to be:
a = input().split() #["12:00","AM"]
then,
print(a[0]) #"12:00"
+ 1
12×12=9
23×23=16
34×34=?
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
0
I hope you'll understand
0
So, 3 tests out of 5 I passed and I do not know why the rest are wrong
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
0
Mission called "Military time"
0
Indeed
0
Omao
0
Okey
0
I'll check it
0
Thanks