0

Please what’s wrong with this

for n in range(str(input())): text = str(input()) print('{} {}'.format(text[::2], text[1::2])

3rd Sep 2020, 12:01 AM
Elijah Oduyemi
Elijah Oduyemi - avatar
12 Answers
+ 1
Mirielle still saying error
3rd Sep 2020, 12:14 AM
Elijah Oduyemi
Elijah Oduyemi - avatar
+ 1
What is the error message?
3rd Sep 2020, 2:02 AM
Jolomi Tosanwumi
+ 1
What do you want the code to actually do?
3rd Sep 2020, 2:03 AM
Jolomi Tosanwumi
+ 1
it should print the even index of a string on one side and odd index on another side
3rd Sep 2020, 3:38 PM
Elijah Oduyemi
Elijah Oduyemi - avatar
+ 1
I guess you meant it should print out the letters with even indices on one side and that of odd indices on the other side. Then you could do something like... text = input() print('{} {}'.format(text[::2], text[1::2])) Your current code didn't work because the argument of the range function is a string. Also setting text = str(input()) inside the for loop will require multiple inputs.
3rd Sep 2020, 4:46 PM
Jolomi Tosanwumi
+ 1
Didnt work also Jolomi Tosanwumi
3rd Sep 2020, 5:36 PM
Elijah Oduyemi
Elijah Oduyemi - avatar
+ 1
It worked on my end...hope you're not making any mistake in syntax.
3rd Sep 2020, 5:49 PM
Jolomi Tosanwumi
+ 1
for n in range(int(input()): text = input() print('{} {}'.format(text[::2], text[1::2])
3rd Sep 2020, 5:50 PM
Elijah Oduyemi
Elijah Oduyemi - avatar
+ 1
is that the same as yours?
3rd Sep 2020, 5:51 PM
Elijah Oduyemi
Elijah Oduyemi - avatar
+ 1
No...it is text = input() print('{} {}'.format(text[::2], text[1::2]))
3rd Sep 2020, 8:20 PM
Jolomi Tosanwumi
+ 1
wow. it worked. thanks so much
3rd Sep 2020, 9:21 PM
Elijah Oduyemi
Elijah Oduyemi - avatar