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 Answers
+ 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