Created
April 26, 2021 19:35
-
-
Save SamirPaulb/7a9ccee65081809b13de0d5f5182e037 to your computer and use it in GitHub Desktop.
Python Pattern Programs - Printing Numbers in Triangle Shape | Column wise | Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Printing Numbers in Triangle Shape | Column wise | Interview Question| reverse Order.py