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?
2 odpowiedzi
+ 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])
+ 1
Thank you