+ 3

for loop

i know i can print letter in string, like: for letter in 'bananasaregreat': print(letter) but, how do i make the output like this?: ban ana sar egr eat

25th Jan 2018, 9:46 AM
Ader
Ader - avatar
2 Answers
+ 9
a = "abcdefghijklmnopqrstuvwxyz" for i in range(0,len(a),3): print(a[i:i+3])
25th Jan 2018, 11:26 AM
David Akhihiero
David Akhihiero - avatar
+ 9
maybe you can put some counter that count to 3 and the when comes to 3 print new line and back counter to 0
25th Jan 2018, 10:05 AM
Vukan
Vukan - avatar