Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SamirPaulb/7a9ccee65081809b13de0d5f5182e037 to your computer and use it in GitHub Desktop.
Save SamirPaulb/7a9ccee65081809b13de0d5f5182e037 to your computer and use it in GitHub Desktop.
Python Pattern Programs - Printing Numbers in Triangle Shape | Column wise | Interview Question
'''
28
27 21
26 20 15
25 19 14 10
24 18 13 9 6
23 17 12 8 5 3
22 16 11 7 4 2 1
'''
def num(n1):
if n1 == 1:
return 1
else:
return n1 + num(n1-1)
n = int(input("Enter how many rows: "))
k = num(n)
for row in range(n):
val = k - row
dec = n -1
for col in range(row+1):
print(format(val,"<3"),end="")
val = val - dec
dec = dec -1
print()
@SamirPaulb
Copy link
Author

Printing Numbers in Triangle Shape | Column wise | Interview Question| reverse Order.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment