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

vertopal.com_forloop_patterns

The document contains various patterns generated using loops in Python, showcasing different shapes made with stars and letters. Patterns include right-angled triangles, pyramids, and mirrored shapes, with varying levels of complexity and alignment. Each pattern is presented with its corresponding code snippet for clarity.

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

vertopal.com_forloop_patterns

The document contains various patterns generated using loops in Python, showcasing different shapes made with stars and letters. Patterns include right-angled triangles, pyramids, and mirrored shapes, with varying levels of complexity and alignment. Each pattern is presented with its corresponding code snippet for clarity.

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

pattern 79

pattern 10

# right angled left aligned triangle


for i in range(1, 6):
# printing stars
print('*' * i)

*
**
***
****
*****

pattern 14

n=5
p=65
for i in range(n):
for j in range(i+1):
print(chr(p+j),end=' ')
print()

A
A B
A B C
A B C D
A B C D E

pattern 25

n=5
p=69
for i in range(n):
# print leading spaces
for j in range(n-i):
print(' ',end=' ')
# print stars
for j in range(i+1):
print(i+1,end=' ')
print()

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
pattern 27

n=5
p=65
for i in range(n):
for j in range(n-i-1):
print(' ',end=' ')
for j in range(i+1):
print(chr(p+i),end=' ')
print()

A
B B
C C C
D D D D
E E E E E

pattern 41

height=5
for i in range(height):
# Print leading spaces
print(" " * (height - i - 1), end="")

# Print letters
for j in range(2 * i + 1):
print(chr(65 + j), end=" ")
print()

A
A B C
A B C D E
A B C D E F G
A B C D E F G H I

pattern 56

n=4
for i in range(n):
for j in range(i,-1,-1):
print(n-j-1,end=' ')
print()
for i in range(1,n):
for j in range(n-i):
print(j+i,end=' ')
print()

3
2 3
1 2 3
0 1 2 3
1 2 3
2 3
3

pattern 55

n=4
for i in range(n+1):
for j in range(i):
print(n-j-1,end=' ')
print()
for i in range(1,n):
for j in range(n-i):
print(n-j-i,end=' ')
print()

3
3 2
3 2 1
3 2 1 0
3 2 1
2 1
1

pattern 52

n = 4
p = 71

for i in range(n):
# print leading spaces
for j in range(2 * i) :
print(' ', end="")
# print letters
for j in range(7 - 2 * i):
print(chr(p), end=" ")

print()
p -= 2

G G G G G G G
E E E E E
C C C
A

pattern 63
rows=4
p=68
for i in range(rows):
for j in range(4-i):
print(' ',end=' ' )
for j in range(i+1):
print(chr(p-j),end=' ')
print()
n=3
for i in range(n,0,-1):
for j in range(n-i+2):
print(' ',end=' ')
for j in range(i):
print(chr(p-j),end=' ')
print()

D
D C
D C B
D C B A
D C B
D C
D

pattern 69

height = 5
for i in range(height, 0, -1):
# Print leading spaces
print(' ' * (height - i), end='')
# Print stars
print('* ' * i)

* * * * *
* * * *
* * *
* *
*

pattern 73

height = 5

# Outer loop for rows


for i in range(height):
# Print spaces
print(" " * i, end="")
# Print letters
for j in range(height - i):
print(chr(69 - j-i), end=" ")
print()

E D C B A
D C B A
C B A
B A
A

pattern 78

n = 5

for i in range(1, n + 1):


# print spaces
for j in range(n - i):
print(' ', end='')
# Print numbers
for j in range(1, i + 1):
print(j, end=' ')
print()

for i in range(n - 1, 0, -1):


# Print spaces
for j in range(n - i):
print(' ', end='')
# Print numbers
for j in range(1, i + 1):
print(j, end=' ')
print()

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

pattern 81

n = 5
for i in range(n):
# Print leading spaces
for j in range(n - i - 1):
print(" ", end="")
# Print the first star
print("*", end="")

# Print spaces
if i > 0:
# print spaces between stars
print(" " * (2 * i - 1), end="")
print("*", end="")
print()

*
* *
* *
* *
* *

pattern 82

n = 5

# Loop for each row


for i in range(n):
# Print leading spaces
for j in range(n - i - 1):
print(" ", end="")

# Print the first star


print("*", end="")

# Print spaces and the second star if it's not the first row
if i > 0:
# print spaces between stars
print(" " * (2 * i - 1), end="")
print("*", end="")

print()

*
* *
* *
* *
* *

pattern 79

height=9
for i in range(1, height//2 + 2): # Rows 1 to 5
# Print leading spaces
print(' ' * (height//2 + 1 - i), end='') # h//2 takes out
decimal value
# Print stars
print('* ' * i)

for i in range(height//2 , 0, -1): # Rows 6 to 9


# Print leading spaces
print(' ' * (height//2 + 1 - i), end='')
# Print stars
print('* ' * i)

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

You might also like