# 25+ Best Pattern Programs in Python for Class 11

Share with others

## Q1. Write a program in Python to print the following pattern

a)

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

```Show AnswerAns.

for i in range(1, 6):
for j in range(1, i+1):
print(j, end = " ")
print()```

b)

5 4 3 2 1

5 4 3 2

5 4 3

5 4

5

```Show AnswerAns.

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

c)

5 5 5 5 5

4 4 4 4

3 3 3

2 2

1

```Show AnswerAns.

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

d)

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

```Show AnswerAns.

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

e)

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

```Show AnswerAns.

for i in range(1, 6):
for j in range(1, i+1):
print(i, end = " ")
print()```

## Pattern Programs in Python

f)

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

```Show AnswerAns.

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

g)

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

```Show AnswerAns.

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

h)

``` `       1    `
`1 2  `
`1 2 3 `
1 2  3  4
1 2 3  4  5 ```
```Show AnswerAns.

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

i)

``` `       1    `
`2 2  `
`3 3 3 `
4 4  4  4
5 5 5  5  5 ```
```Show AnswerAns.

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

j)

``` `       1    `
`2 1  `
`3 2 1 `
4 3  2  1
5 4 3  2  1```
```Show AnswerAns.

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

## Pattern Programs in Python

k)

1

2 1

3 2 1

4 3 2 1

5 4 3 2 1

```Show AnswerAns.

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

l)

1

2 3

4 5 6

7 8 9 10

```Show AnswerAns. (This triangle is called Floy'd triangle)

c = 1
st = 2
for i in range(3):
for j in range(1, st):
print(c, end=" ")
c += 1
print()
st = st+1
```

m)

1

2 3 4

5 6 7 8 9

```Show AnswerAns.

c = 1
st = 2
for i in range(3):
for j in range(1, st):
print(c, end=" ")
c += 1
print()
st = st+2

```

n)

0

0 1

0 2 4

0 3 6 9

0 4 8 12 16

```Show AnswerAns.

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

o)

0
0 1
0 1 4
0 1 4 9
0 1 4 9 16

```Show AnswerAns.

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

## Pattern Programs in Python

p)

1
4 4
9 9 9
16 16 16 16
25 25 25 25 25

```Show AnswerAns.

for i in range(1,6):
for j in range(1,i+1):
print(i*i, end = " ") #print(i**2, end = " ") can also be written
print()```

q)

1
3 3
5 5 5
7 7 7 7
9 9 9 9 9

```Show AnswerAns.

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

r)

```*
*   *
*   *   *
*   *   *   *
*   *   *   *   *```
```Show AnswerAns.

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

s)

```*   *   *   *   *
*   *   *   *
*   *   *
*   *
*```
```Show AnswerAns.

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

t)

```          *
* *
* * *
* * * *
* * * * *         ```
```Show AnswerAns.

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

## Pattern Programs in Python

u)

```1  2  3  4  5
1  2  3  4  5
1  2  3  4  5
1  2  3  4  5
1  2  3  4  5```
```Show AnswerAns.

for i in range(6):
for j in range(1,6):
print(j, end = " ")
print()```

v)

```1  1  1  1  1
2  2  2  2  2
3  3  3  3  3
4  4  4  4  4
5  5  5  5  5  ```
```Show AnswerAns.

for i in range(1,6):
for j in range(1,6):
print(i, end = " ")
print()```

w)

```A
A  B
A  B  B
A  B  C  D
A  B  C  D  E```
```Show AnswerAns.

str = "A B C D E"
for i in range(1, 6):
print(str[ : i*2])```

x)

```A
B  B
C  C  C
D  D  D  D
E   E  E   E   E ```
```Show AnswerAns.

str = "ABCDE"
for i in range(5):
print(str[i]*(i+1))```

y)

```           *
* * *
* * * * *
* * * * * * *

```
```Show AnswerAns.

num = 5
for i in range (1, num + 1):
sp = (num - i) * "  "
print(sp, end = " ")
for k in range(i, 1, -1):
print("*", end = " ")
for j in range(1, i + 1):
print("*", end = " ")
print()```

## Pattern Programs in Python

z)

```Show AnswerAns i)

n = 3
for i in range (1, n + 1):
sp = (n - i) * " "
sym =  (2 * i - 1) * "*"
print(sp, sym)
for j in range(n - 1, 0, -1):
sp = (n - j) * " "
sym = (2 * j - 1)* "*"
print(sp, sym)

ii)

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

iii)

str = "123456"
for i in (str):
print(" " * int(i) + str[0 : len(str) - int(i)])

OR

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

iv)

num = 3
k = 0
for i in range (1, num + 1):
sp = (num - i)*" "
print(sp, end=' ')
while (k != (2 * i - 1)) :
if (k == 0 or k == 2 * i - 2) :
print("*", end= "")
else :
print(" ", end = "")
k = k + 1
k = 0
print( )
for j in range (num - 1, 0, -1):
sp = (num - j) * " "
print(sp, end=" ")
k = (2 * j - 1)
while (k > 0) :
if (k==1 or k == 2 * j - 1):
print("*",end="")
else:
print(" ",end="")
k = k - 1
print( ) ```

## Pattern Programs in Python

aa)

p
p y
p y t
p y t h
p y t h o
p y t h o n

```Show AnswerAns

str = "python"
for i in range(len(str)+1):
for j in range(i):
print(str[j], end = " ")
print()
```

ab)

```           1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5```
```Show AnswerAns.

num = 5
for i in range (1, num + 1):
sp = (num - i) * "  "
print(sp, end = " ")
for k in range(i, 1, -1):
print(i, end = " ")
for j in range(1, i + 1):
print(i, end = " ")
print()```

## Pattern Programs in Python

Disclaimer : I tried to give you the correct code of ” Pattern Programs in Python , but if you feel that there is/are mistakes in ” Pattern Programs in Python ” given above, you can directly contact me at csiplearninghub@gmail.com. Book and Study material available on CBSE official website are used as a reference to create above “ Pattern Programs in Python “.

## 40 Practice Questions on Data Structure

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series

Share with others