+ 3
Why the code doesn't show odd letters in the word? Also, The letters should be sorted in ascending order
text = "apple" t = sorted(text) for i in range(len(text)) : if i % 2 == 0: print(t[I])
6 ответов
+ 2
Hi, can you please tag Python as the relevant language up there? ☝
And tell me how output should be by that input, coz I'm not getting what you mean by "odd letters"
+ 2
Thank you very much 😇
+ 2
Sort alphabetically
+ 1
Try now you did one mistake in print statement you wrote capital I instead of small i .
text = "apple"
t = sorted(text)
for i in range(len(text)) :
if i % 2 == 1:
print(t[i])
0
text = "apple"
t = sorted(text)
for i in range(len(text)) :
if i % 2 == 1:
print(t[i],end="") #end ="" for printing in same line...
Edit : Марина for odd only.. Oh. Edited.
i%2=0, =>I is even, i%2=1 odd.
0
Yes. Sorted works..check
text = "apple"
t = sorted(text)
print(t) #output : a, e, l, p, p