Crunch Crunch - 1 month ago 5
Python Question

How to make a number triangle

I'm trying to make a triangle that appears like


1
12
123
1234
12345


This code causes it to just print 1 over and over

def line(n):
print('1' *n)

def triangle(n):
for i in range(1,n+1):
line(i)

Answer

What about (assuming Python 3):

def line(n):
    for i in range(n):
        print(i+1, end='')
    print()