String Operation task: | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

String Operation task:

Take a string as input and output each letter of the string on a new line, repeated N times, where N is the position of the letter in the strings. Below is my code: Str = input(ā€œ ā€œ) for i in range(len(Str)): print(i*Str[i]) What could be wrong, why is it not starting from the first letter?

9th Jan 2022, 5:52 PM
Adewale Obalanlege
Adewale Obalanlege - avatar
2 Respostas
+ 1
Adewale Obalanlege range should start from 1 but it is starting with 0 so multiply with 0 would give empty value so do this: for i in range(1, len(Str) + 1): print (i * Str[i - 1])
9th Jan 2022, 5:58 PM
AĶ¢J
AĶ¢J - avatar
+ 1
Thank you
9th Jan 2022, 6:04 PM
Adewale Obalanlege
Adewale Obalanlege - avatar