0% found this document useful (0 votes)
10 views2 pages

Python_Pattern_Questions_Answers

The document contains a series of Python code snippets for various pattern printing exercises, including shapes like squares, triangles, pyramids, and number patterns. Each pattern is generated based on user input for the number of rows or size. The examples demonstrate fundamental programming concepts such as loops and string manipulation in Python.

Uploaded by

karanmundhava41
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)
10 views2 pages

Python_Pattern_Questions_Answers

The document contains a series of Python code snippets for various pattern printing exercises, including shapes like squares, triangles, pyramids, and number patterns. Each pattern is generated based on user input for the number of rows or size. The examples demonstrate fundamental programming concepts such as loops and string manipulation in Python.

Uploaded by

karanmundhava41
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/ 2

Python Pattern Printing Questions and Answers

1. Square of Stars
n = int(input("Enter a number: "))
for i in range(n):
print("*" * n)

2. Left-Aligned Triangle
n = int(input("Enter a number: "))
for i in range(1, n + 1):
print("*" * i)

3. Right-Aligned Triangle
n = int(input("Enter a number: "))
for i in range(1, n + 1):
print(" " * (n - i) + "*" * i)

4. Pyramid Pattern
n = int(input("Enter a number: "))
for i in range(1, n + 1):
print(" " * (n - i) + "*" * (2*i - 1))

5. Inverted Left-Aligned Triangle


n = int(input("Enter a number: "))
for i in range(n, 0, -1):
print("*" * i)

6. Inverted Pyramid
n = int(input("Enter a number: "))
for i in range(n, 0, -1):
print(" " * (n - i) + "*" * (2*i - 1))

7. Number Triangle
n = int(input("Enter a number: "))
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="")
print()

8. Repeated Number Triangle


n = int(input("Enter a number: "))
for i in range(1, n + 1):
print(str(i) * i)

9. Floyd's Triangle
n = int(input("Enter number of rows: "))
num = 1
for i in range(1, n + 1):
for j in range(i):
print(num, end=" ")
num += 1
print()

10. Alphabet Pattern


n = int(input("Enter a number: "))
for i in range(1, n + 1):
for j in range(65, 65 + i):
print(chr(j), end="")
print()

You might also like