I was given this problem in a Python class I'm taking. 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 string.
Here is my first attempt:
string = input()
for i in string:
n = string.index(i) + 1
print(i * n)
'''
but the output for the input: 'awesome', was:
'''
a
ww
eee
ssss
ooooo
mmmmmm
eee
'''
The output I want is:
'''
a
ww
eee
ssss
ooooo
mmmmmm
eeeeeee
'''
I was able to figure out a different way of doing it, that ended up giving me the correct output:
string = input()
i = 0
while i < len(string):
print(string[i] * (i + 1))
i += 1
a
ww
eee
ssss
ooooo
mmmmmm
eeeeeee
My question now is why my first attempt does not give me the expected output.