M2_Simple Programs
M2_Simple Programs
in
Dept. of MCA
Dept. of MCA
Dept. of MCA
Program to print half pyramid using * *
**
***
****
*****
rows = int(input("Enter number of rows: "))
for i in range(rows):
for j in range(i+1):
print("* ", end="")
print()
Dept. of MCA
Program to print half pyramid a using
numbers 1
12
123
1234
12345
for j in range(i+1):
print()
Program to print half pyramid using alphabets
BB
CCC
Dept. of MCA
DDDD
EEEEE
Inverted half pyramid using * *****
****
***
**
*
rows = int(input("Enter number of rows: "))
print()
Inverted half pyramid using numbers
12345
1234
123
12
1
rows = int(input("Enter number of rows: "))
Dept. of MCA
for i in range(rows, 0, -1):
print()
Program to print full pyramid using * *
rows = int(input("Enter number of rows: ")) ***
k=0 *****
for i in range(1, rows+1): *******
for space in range(1, (rows-i)+1): *********
print(end=" ")
while k!=(2*i-1):
Dept. of MCA
print("* ", end="")
k += 1
k=0
print()
Full Pyramid of Numbers 1
rows = int(input("Enter number of rows: ")) 232
k=0 34543
count=0 4567654
count1=0 567898765
for i in range(1, rows+1):
for space in range(1, (rows-i)+1):
print(" ", end="")
count+=1
while k!=((2*i)-1):
Dept. of MCA
if count<=rows-1:
print(i+k, end=" ")
count+=1
else:
count1+=1
print(i+k-(2*count1), end=" ")
k += 1
count1 = count = k = 0
print()
Program Assignments
Dept. of MCA
• Python Program to Left Rotate a List by R Times
Dept. of MCA