First Pattern:
n = int(input('Enter pyramid height: '))
for i in range(n, 0, -1):
print(' ' * (i - 1) + '*' * (n - i + 1))
Output:
Enter pyramid height: 4
*
**
***
****
Second Pattern:
n = int(input('Enter pyramid height: '))
for i in range(n, 0, -1):
print(' ' * (n - i), end = '')
for j in range(i, 0, -1):
print(i, end = '')
print()
Alternative Method:
n = int(input("Enter pyramid height: "))
for i in range(n,0,-1):
print(" " * (n-i), end = '')
print(str(i) * i)
Output:
Enter pyramid height: 4
4444
333
22
1
n = int(input('Enter pyramid height: '))
for i in range(n, 0, -1):
print(' ' * (i - 1) + '*' * (n - i + 1))
Output:
Enter pyramid height: 4
*
**
***
****
Second Pattern:
n = int(input('Enter pyramid height: '))
for i in range(n, 0, -1):
print(' ' * (n - i), end = '')
for j in range(i, 0, -1):
print(i, end = '')
print()
Alternative Method:
n = int(input("Enter pyramid height: "))
for i in range(n,0,-1):
print(" " * (n-i), end = '')
print(str(i) * i)
Output:
Enter pyramid height: 4
4444
333
22
1
No comments:
Post a Comment