I want to print the current element and the old element of my for loop:
Output:
1
1 3
1 3 5
1 3 5 7
1 3 5 7 9
for current_element in range(1,10,2):
print(current_element, end= ' ')
I get only the last line " 1 3 5 7 9 "
>Solution :
You’re not getting the last row but the right diagonal, as you print each value on the same line
You need to save the previous values to achieve your triangle output
values = []
for current_element in range(1, 10, 2):
values.append(current_element)
print(*values)
1
1 3
1 3 5
1 3 5 7
1 3 5 7 9