0% found this document useful (0 votes)
24 views18 pages

Patterns 2

The document provides examples of different patterns that can be printed in Python like stars, numbers, and letters. It explains how to print these patterns using loops and conditions by manipulating the number of spaces and stars in each line.
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)
24 views18 pages

Patterns 2

The document provides examples of different patterns that can be printed in Python like stars, numbers, and letters. It explains how to print these patterns using loops and conditions by manipulating the number of spaces and stars in each line.
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/ 18

Pattern Printing - 2

Lecture- 8

Raghav Garg
Ques : Print the given pattern

**** *
* *
*

****
- -
- -
-

*
* *
*

****
- -

-
-
+
-

*
* *
*

****
-

*
* *
*

Rhombus
*Ques : Print the given pattern

* 1 -> I

***
-

- -

2 *
*
*

13
-

*****
--
->
+
-

3 *
* * -S

*******
*
-

*
-

y **
* **** e7

2i-1
j = 1 to

Star Pyramid
*Ques : Print the given pattern not &nsp
nor of
d

of
*
1 - no.
---
- - -

*** ↓ spaces
2 ***
2--
-
- -
stars

*****
* * *
3 * *
3 -
-

*******
4 - *
*
* ** * *
4
is lines
5 *** * * *
* ** no.
of

) penli line me
spaces hange. &
usb--;
Ust 1, nst+=2
2)
=

Star Pyramid
i x & BY
=

Output

I
nst y B $7
=

6 X
3 - -

nsp 2
=

X 0-1 X
O ⑧ -
XX
-

⑧ * * * * X

S
-

n
3+
=

*
*
* * *
Ques : Print the given pattern

1
I
I
I ↓ I
- - -

121
2
2
-
212 2 I
t f
3
12321
->
3 -
3123 32 I
Y
1234321 Y y1234 4 32 1

Number Pyramid Palindrome


I
L
--- I
I I
2--12 1
2 2 I

3- 1232 1
3 32 I

y 1234 321
432 1
Y

S4321

S

j i;j,1;j
--
=
*Ques : Print the given pattern usp & ust

*
I
---

***
*

E *****
- -

* X *
*

*******
-

* A & * * * X *
X

***** * * * X

***
-

--
* R= I

*
n 2
=

7 - - -

n 3
=

n 4
=

2n-1 lines
printline

Star Diamond
*Ques : Print the given pattern
3ex-/+
4 n =

nsp 1 +
n
=
-

I
* =2(2
***
---

ust 1
=

*****
- -

3 n

↓ ↳
Y ******* Styline
*****
-
utline
6
***
- -

7
*
- - -

i 1
=
to i c 24n
= -
1

Star Diamond
n Y
=

I
7 nst y =

BS A $BX-1 Output
=

nsp BxX ONX BU


=

o - - -
X

i RBM$6 A8
=

o - -
Xx a

3 o -
x x x x X
-

· x* * * * * *

o -
* * * * *
-- -
*

* * * x x x
2 -
- 8 -
-

3
* *

"
* *
*
- X
-

- -

· -

*
*
*
* * * *
- * *
* * *

- - * * *

7 - - -
*
Ques : Print the given pattern
nsp 1, nsk 2
+=

*******
=

-> 2n-1 stars

I
*** *** -
* *
* 1 -
* *
*

** **
2
- - -
- * * +2 - - -
t *
*

* *
3 3
- * - - -
*

m 3 14
=

A *

2 A X

3 A
n, m r
=
-
1
-

L
1 1
3 j m
=
+ -

m
=

Star Bridge
*Ques : Print the given pattern
1234567
I
123 567-
123 - 567
2
12 67
- -
12
t - - - t
67

3 1 -
7
-
I - - - -
I

n Y
=

m n
= -
1 3
=

Number Bridge
**Ques : Print the given pattern Ellimate
I
4444444 n 1
=
n 2
=
n 3
=

2
4333334 I 222
33333
3 4 3 2 2 2 3 4 32223
212
2123
4321234 3
I 4322234
212
2123
33333
6 4 3 3 3 3 3 4

7 4 4 4 4 4 4 4

n 4
=

i 1
=
to 2 *n-1

Number SPIRAL

I I 12 3 4 -
6
I 11 I I
2 I I I I
12222 2 I

123332 I 2 22

'
I 2

23 4 32 1

!
3 1233
23332 I
Y 1 2 3 4
22222 1

I I I I
L
I 11
n 4
=

n 4
=
each is cell has

a value min (i,j)


variable
e

1234567- j I 2 34567
I I 11 I 1 I I I I 111 II I

2 I 2222 2 I 2 I 22222
2

233333

3!
I 23332 I I

' 23 4 32 1 2 34444

! 234555
E
23332 I

6 22222 1 6 34566

7 I 234567
1 I I 11 I
h ↓
ai n 4
=
2n-1 lines

i a + 2n
=

a 2n
=
-
1
Final Changes

1 - n -0

2 3 n -
1

3 I n
-
2

x - n - x 1
+
What’s in the next lecture?
A head start to modern programming: Functions!

You might also like