0% found this document useful (0 votes)
5 views

Computer programming assignment.docx2 (3)

The document is a computer programming assignment prepared by Birhanu Bogale, focusing on various pyramid and triangle patterns using loops in Python. It includes code snippets for simple pyramids, inverted pyramids, number pyramids, and alphabet pyramids, among others. The assignment is to be submitted to Instructor Kinde Mekria by May 6, 2025.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computer programming assignment.docx2 (3)

The document is a computer programming assignment prepared by Birhanu Bogale, focusing on various pyramid and triangle patterns using loops in Python. It includes code snippets for simple pyramids, inverted pyramids, number pyramids, and alphabet pyramids, among others. The assignment is to be submitted to Instructor Kinde Mekria by May 6, 2025.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Computer programming assignment -III

SECTION -12

 Prepared by:

BIRHANU BOGALE UGR/3940/17

Submitted to: INS. KINDE MEKRIA

Submission date: may,6 2025

1
#a) SIMPLE PYRAMID
n=6
for i in range(1, n):
for j in range(1,i+1):
print("*", end=" ")
print()

#b) ROTATED SIMPLE PYRAMID


n=5
for i in range (1,n+1):
for j in range (n-1,i-1,-1):
print(" ",end=" ")
for k in range(1,i+1):
print('*',end=' ')
print()

#c) INVERTED PYRAMID


for i in range(1, 6):
for j in range(5, i - 1, -1):
print("*", end=" ")
print()

#d) ROTATED INVERTED PYRAMID


n=5
for i in range(n, 0, -1):
for j in range(n - 1, i - 1, -1):
print(" ", end=" ")
for k in range(1, i + 1):
print("*", end=" ")
print()

2
#e) TRIANGLE
p_height = 6
for i in range(1, p_height):
for k in range(p_height - 1, i - 1, -1):
print(" ", end="")
for j in range(1, i + 1):
print("* ", end="")
print()

#l) INVERTID TRIANGLE


p_height = 5
for i in range(p_height, 0, -1):
for k in range(p_height - 1, i - 1, -1):
print(" ", end="")
for j in range(i, 0, -1):
print("* ", end="")
print()

#f) NUMBER PYRAMID


n=5
for i in range(1, n):
for j in range(1,i+1):
print(i, end=" ")
print()

#g) CONTINUOUS NUMBER PYRAMID


rows=4
num = 1
for i in range(1, rows + 1):
for j in range(i):
print(num, end=" ")
num += 1
print()

3
#h) ROTATED NUMBER PYRAMID
n=4
for i in range(n):
print(" " * (n - i - 1), end="")
for j in range(i + 1):
print(i + j + 1, end=" ")
print()

#i) PALINDROME TRIANGLE


n=4
for i in range(1, n + 1):
print(" " * (n - i), end="") # Leading spaces
for j in range(i): # Increasing part
print(i + j, end=" ")
for j in range(i - 2, -1, -1): # Decreasing part
print(i + j, end=" ")
print()

#j) ALPHABET PYRAMID


n=4
for i in range(0, n):
for j in range(0,i+1):
print(chr(i + 65), end=" ")
print()

#k) CONTINUOIS ALPHABET PYRAMID


rows=4
char_val = 65
for i in range(1, rows + 1):
for j in range(i):
print(chr(char_val), end=" ")
char_val += 1
print()

4
2)

name = "BIRHANUBOGALEMEKURIYAW" * 2
index = 0
rows = 11
max_width = 7
for i in range(1, max_width + 1):
spaces = max_width - i
print(" " * spaces, end="")
for j in range(i):
if index < len(name):
print(name[index], end=" ")
index += 1
else:
print("*", end=" ")
print()
for i in range(max_width - 1, 0, -1):
spaces = max_width - i
print(" " * spaces, end="")
for j in range(i):
if index < len(name):
print(name[index], end=" ")
index += 1
else:
print("*", end=" ")
print()

You might also like