+ 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])

2nd Oct 2020, 1:56 PM
Марина
Марина - avatar
6 Respostas
+ 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"
2nd Oct 2020, 2:01 PM
Ipang
+ 2
Thank you very much 😇
2nd Oct 2020, 2:04 PM
Марина
Марина - avatar
+ 2
Sort alphabetically
2nd Oct 2020, 2:07 PM
Марина
Марина - avatar
+ 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])
2nd Oct 2020, 2:01 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
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.
2nd Oct 2020, 2:01 PM
Jayakrishna 🇮🇳
0
Yes. Sorted works..check text = "apple" t = sorted(text) print(t) #output : a, e, l, p, p
2nd Oct 2020, 2:10 PM
Jayakrishna 🇮🇳