I have to write a program in python that will take a number and print a right triangle attempting to use all numbers from 1 to that number. For example:
Enter number: 10
Output:
7 8 9 10
4 5 6
2 3
1
Enter number: 6
Output:
4 5 6
2 3
1
Enter number: 20
Output:
11 12 13 14 15
7 8 9 10
4 5 6
2 3
1
For which I have written the following function
def print_right_triangle(num):
c = 1
k = 0
l = []
while(k < num-1):
v = []
for i in range(c):
v.append(k+1)
k += 1
c += 1
if k > num:
break
l.append(v)
p = len(l)
for i in range(p):
for j in l[p-(i+1)]:
print(j, end=' ')
print()
return None
print_right_triangle(10)
It's giving the same output and solved my problem. I was wondering is there any more pythonic way to do this