You are given a positive integer (example: N = 6). Print a numerical triangle of height like the one below:
1
22
333
4444
55555
Use no more than two lines of code. Use a for loop and print function only. You can't use anything related to strings. N is an input.
What I tried:
for i in range(1,int(input())):
print(*range(1, i+1))
my output:
1
1 2
1 2 3
1 2 3 4
One way to get the triangle indicated (without using strings) is to treat the output as numbers and to calculate those numbers:
N = 6
for i in range(1, N):
print(sum(10**j for j in range(i)) * i)
Output as requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With