0% found this document useful (0 votes)
89 views435 pages

Sant Nandlal Smriti Vidya Mandir

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)
89 views435 pages

Sant Nandlal Smriti Vidya Mandir

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/ 435

SANT NANDLAL SMRITI

VIDYA MANDIR

AISSE
2023-2024
COMPUTER SCIENCE

NAME:-RITESH MHATO
CLASS:-11 SCIENCE “A”
ROLL NO:-23
SUBJECT TEACHER:-Saikat
Kumar Roy
Certificate
This is to certify that RAJDEEP CHOUDHURY of class- XI SCIENCE “A”, Roll No-
23 of SantNandlalSmritiVidyaMandir has successfully completed this project
with great satisfactory results under supervisor based on the syllabus of session
2023-2024 examination.

MR. SAIKAT KUMAR ROY MRS. NEELKAMAL SINHA


(HOD, Computer Science)(PRINCIPAL)

2
Acknowledgement
I, RITESH MHATO , of XI SCIENCE “A”, Roll No- 23, have
completed Computer Science Project work under the guidance of
our respected teachers Mr. Saikat Kumar Roy.

As my heartiest gratitude, I would like to express my sincere


thanks to my honourable teachers who were my consultant and
guide. I would also like to acknowledge the support of my
parents and friends who had helped me in every step of my
project.

3
Index
Exp.N Date Experiment Page.
o. No.
1 4.5.23 Write a program in python to print your name 5 times 25-26
2 10.5.2 Write a program in python to find the sum of two digits 27-28
3
3 10.5.2 Write a program in python to find the difference of two 29-30
3 numbers
4 10.5.2 Write a program in python to find the multiplication of two 31-32
3 numbers
5 10.5.2 Write a program in python to find the division of two 33-34
3 number
6 10.5.2 Write a program in python to find the greatest of two 35-36
3 numbers
7 16.5.2 Write a program in python to find the greatest of three 37-38
3 numbers
8 16.5.2 Write a program in python to check whether a Number is 39-40
3 even or odd
9 16.5.2 Write a program in python to find the area of a circle 41-42
3
10 16.5.2 Write a program in python to find the roots of a quadratic 43-44
3 equation
11 16.5.2 Write a program in python to find whether a Number is 45-46
3 positive or negative
12 16.5.2 Write a program in python to find the simple interest 47-48
3
13 16.5.2 Write a program in python to find the smallest of three 49-50
3 numbers
14 16.5.2 Write a program in python to find 51-52
3 theaddition,subtraction,multiplication,division of two
numbers
15 19.5.2 Write a menu driven program in python to find simple 53-54
3 interest and compound interest
16 19.5.2 Write a menu driven program in python to find area of 55-60
3 square,rectangle, circle, trapizum,rhombus,triangle and
volume of cube,cuboid,cylinder,sphere,hemisphere,cone
17 20.5.2 Write a program in python to find swapping of two 61-62
3 numbers
18 20.5.2 Write a program in python to swap two numbers without 63-64
3 using third variable
19 20.5.2 Write a program in python to check whether a Number is 65-66
3 prime Number or not
20 20.5.2 Write a program in python to Count and display prime 67-68
3 number between certain range
21 26.5.2 Write a program in python to find the sum of n natural 69-70
3 numbers
22 26.5.2 Write a program in python to find the sum of even and 71-72
3 odd number within a certain range
4
23 26.5.2 Write a program in python to find the factorial of a 73-74
3 number
24 27.5.2 Write a program in python to find fibonacci series 75-76
3
25 27.5.2 Write a program in python to print the following pattern 77-78
3 *

**

***
26 27.5.2 Write a program in python to print the following pattern 79-80
3 *****

****

***

**

*
27 3.7.23 Write a program in python to print the following pattern 81-82
*

**

***

****
28 4.7.23 Write a program in python to print the following pattern 83-84
*

**

***

****
29 4.7.23 Write a program in python to print the following pattern 85-86
*****

****

***

**

*
30 4.7.23 Write a program in python to print the following pattern 87-88
*

**

***

****

*****

****

***

**

*
31 4.5.23 Write a program in python to print the following pattern 89-91
*

**

5
***

****

*****

****

***

**

**

***

****
32 4.7.23 Write a program in python to print the following pattern 92-93
*

**

* *

* *

*****
33 6.7.23 Write a program in python to print the following pattern 94-95
*

**

* *

* *

* *

* *

* *

**

*
34 6.7.23 Write a program in python to print the following pattern 96-98
*

**

* *

**

**

* *

**

*
35 6.7.23 Write a program in python to print the following pattern 99-
* 100
**

*#*

*##*

6
*****
36 6.7.23 Write a program in python to print the following pattern 101-
* 102
***

*****

*******
37 6.7.23 Write a program in python to print the following pattern 103-
* 104
**

*#*

*##*

*#@#*
38 6.7.23 Write a program in python to print the following pattern 105-
* 107
* *
* *
* *
* *
* *
**
* *
*********
* *
* *
* *
* *
* *
* *
* *
*
39 11.7.2 Write a program in python to print the following pattern 108-
3 ***** 109
* *

* *

* *

*****
40 11.7.2 Write a program in python to print the following pattern 110-
3 ***** 111

* ** *

** **

** **

*****
41 11.7.2 Write a program in python to print the following pattern 112-
3 ********* 114
* * * *

* * * *

** * *

* *

** * *

7
* * * *

* * * *

*********
42 13.7.2 Write a program in python to print the following pattern 115-
3 ************* 116
***********

*********

*******

*****

***

*
43 13.7.2 Write a program in python to print the following pattern 117-
3 * * 118
** **

*** ***

**** ****

***** *****

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

44 14.7.2 Write a program in python to print the pattern 119-


3 * 120
*

*****

*
45 17.7.2 Write a program in python to print the following pattern 121-
3 1 122
12

123

1234

12345
46 17.7.2 Write a program in python to print the following pattern 123-
3 1 124
21

321

4321

54321

654321
47 17.7.2 Write a program in python to print the following pattern 125-
3 54321 126
4321

321

8
21

1
48 17.7.2 Write a program in python to print the following pattern 127-
3 54321
128
5432

543

54

5
49 17.7.2 Write a program in python to print the following pattern 129-
3 1 130
23
456
7 8 9 10
50 17.7.2 Write a program in python to print the following pattern 131-
3 1 132
32

654

10 9 8 7

15 14 13 12 11
51 17.7.2 Write a program in python to print the following pattern 133-
3 * 134
*@*

*@#@*

*@#@#@*

*********
52 17.7.2 Write a program in python to print the following pattern 135-
3 1 136
1 1

1 2 1

1 3 3 1

1 4 6 4 1
53 19.7.2 Write a program in python to print the following pattern 137-
3 1 138
121

12321

1234321

123454321
54 20.7.2 Write a program in python to print the following pattern 139-
3 1 140
212

32123

4321234

*@@@*

* @ *

9
*
55 21.7.2 Write a program in python to print the following pattern 141-
3 12345 142
4 4

3 3

2 2

54321
56 24.7.2 Write a program in python to print the following pattern 143-
3 7 8 9 10 144
456

23

23

456

7 8 9 10
57 25.7.2 Write a program in python to print the following pattern 145-
3 1 146
2 3

4 5

6 7 8 9
58 25.7.2 Write a program in python to print the following pattern 147-
3 1 148
2 3

4 5

6789

10 11

12 13

14
59 28.7.2 Write a program in python to print the following pattern 149-
3 A 150
AB

ABC

ABCD

ABCDE
60 28.7.2 Write a program in python to print the following pattern 151-
3 A 152
AB

ABC

ABCD

ABCDE
61 28.7.2 Write a program in python to print the following pattern 153-
3 A 154

10
BA

CBA

DCBA

EDCBA
62 28.7.2 Write a program in python to print the following pattern 155-
3 A 156
CB

FED

JIHG

ONMLK
63 28.7.2 Write a program in python to print the following pattern 157-
3 A 158
ABC

ABCDE

ABCDEFG

ABCDEFGHI
64 31.7.2 Write a program in python to print the following pattern 159-
ONMLK 160
JIHG

FED

CB

A
65 31.7.2 Write a program in python to print the following pattern 161-
3 ABCDEDCBA 162
ABCDCBA

ABCBA

ABA

A
66 31.7.2 Write a program in python to print the following pattern 163-
3 EDCBABCDE 164
DCBABCD

CBABC

BAB

A
67 1.8.23 Write a program in python to print the following pattern 165-
A 166
B1B

C121C

D12321D

EDCBABCDE
68 2.8.23 Write a program in python to print the following pattern 167-
1 168
AB
123
11
ABCD
69 2.8.23 Write a program in python to print the following pattern 169-
1 170
CBA

54321

GFEDCBA
70 4.8.23 Write a program in python to print the sum of series 171-
172
1+2+3+4……+N

71 4.8.23 Write a program in python to print the sum of series 173-


174
1-2+3-4……N
72 4.8.23 Write a program in python to print the the sum of series 175-
176
-1+1/2-1/3+……N
73 4.8.23 Write a program in python to print the sum of series 177-
178
1+(1+2)+(1+2+3)….N
74 4.8.23 Write a program in python to print the sum of series 179-
180
x+x²+x³+…….
75 11.8.2 Write a program in python to print the sum of series 181-
3 182
1-x/2+x³/3-x⁴/4……
76 16.8.2 Write a program in python to print the sum of series 183-
3 184
1-x/2!+x²/3!.....
77 21.8.2 Write a program in python to print the sum of series 185-
3 186
1-x²/3!+x⁴/6!......N
78 21.8.2 Write a program in python to print the sum of series 187-
3 188
1-X5/7!+X10/14!....N
79 21.8.2 Write a program to check whether a Number is a 189-
3 palindrome or not 190

80 21.8.2 Write a program in python to check whether a Number is 191-


3 armstrong or not 192
81 21.8.2 Write a python program to print the series 193-
3 194
-5,10,-15,20…N
82 21.8.2 Write a program in python to print the series 195
3
2,9,28,65…N
83 21.8.2 Write a python program to print the series 196
3
0,6,24,60…N
84 21.8.2 Write a program in python to print the series 197
3
-6x³/5!+24x5/7!-60x7/9!....N
12
85 25.8.2 Write a program in python to check a Number is a special 198-
3 Number or not 199

86 25.8.2 Write a program in python to check a Number is a perfect 200


3 Number or not

87 25.8.2 Write a program to check whether a number is a magic 201-


3 Numbers(1) or not 202
88 25.8.2 Write a program in python to check whether a number is 203
3 a magic Number(2) or not. [55=5+5=10=1+0=1]

89 25.8.2 Write a python program to check whether a Number is a 204-


3 neon number or not 205
90 25.8.2 Write a python program to Count and print palindrome 206
3 Number within certain range

91 25.8.2 Write a python program to Count and print armstrong 207-


3 Number within certain range 208

92 25.8.2 Write a python program to Count and print special 209


3 Number within certain range
93 25.8.2 Write a python program to Count and print perfect 210
3 Number within certain range
94 25.8.2 Write a python program to Count and print magic 211-
3 Numbers (1)Number within certain range 212
95 25.8.2 Write a python program to Count and print magic 213
3 Number(2) within certain range

96 25.8.2 Write a python program to Count and print neon number 214
3 within certain range
97 07.10. Write a program to take input in a string and count the number of vowels and 215
23 consonants and all other character
98 07.10. Write a program to print the pattern using string 216
23 C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
99 07.10. Write a program to reverse a string 217
23
100 07.10. Write a program to print the pattern using string 218
23 C
CO
C M
C P
C U
C T
C E

13
COMPUTER

Write a program to take input a string and reverse the 219


101 11.10. string without changing the meaning[I am a boy]→[boy a
23 am I]
102 11.10. Write a program to input a string and reverse the meaning of the word 220
23 without changing the string [I am a boy]→[I ma a yob]
103 11.10. Write a program to input a string and count the number of 221-
23 character,alphabet,digits,vowels,spaces,consonants and special character 222
104 12.10. Write a program to check a string is palindrome or not 223
23
105 13.10. Write a program to input a string and print a string that capitalize every other 224
23 character in the string[ School→ScHoOl]
106 3.11.2 Write a program to input a string and print the first letter in lower case of that 225
3 string only [I am a boy]→[I Am A Boy]
107 6.11.2 Write a program to input elements in a list METHOD-1 226
3
108 6.11.2 Write a program to input elements in a list METHOD-2 227
3
109 7.11.2 Write a program to input elements in a list and shift all the negative elements 228
3 to the left of the list
110 7.11.2 Write a program to input elements in a list and search the element using linear 229
3 search
111 8.11.2 Write a program to input elements in a list and search the element using 230-
3 binary search 231
112 9.11.2 Write a program to input elements in a list and print the second smallest 232-
3 element in a list 233
113 9.11.2 Write a program to input elements in a list and shift the first half of the 234
3 elements to other half
114 9.11.2 Write a program to input elements in a list and print the second largest 235
3 element in a list
115 9.11.2 Write a program to input elements in a list and to remove the duplicate 236
3 element from the list
116 29.11. Write a program to input elements in a list and sort the list using bubble sort 237
23 technique
117 29.11. Write a program to input elements in a list and sort the list using insertion sort 238
23 technique
118 6.12.2 Write a program in python to find the sum of two matrices 239-
3 240
119 6.12.2 Write a program in python to find the difference of two matrices 241-
3 242
120 6.12.2 Write a program in python to find the multiplication of two matrices 243-
3 244
121 12.12. Write a program to take input in a matrix and transpose it 245
23
122 12.12. Write a program to input a matrix and print the primary and secondary 246-
14
23 diagonals 247
123 Write a program to print the sum of diagonals 248-
249
124 Write a program to print the upper and lower half of a square matrix 250-
251
125 13.12. Write a program using function to find the sum of two number 252-
23 #Having argument but no returning value 253
126 13.12. Write a program using function to find the sum of two number 254-
23 #Having argument but returning value 255
127 13.12. Write a program using function to find the sum of two number 256-
23 #Having no argument but returning value 257
128 13.12. Write a program using function to find the sum of two number 258-
23 #Having no argument but no returning value 259
129 13.12. Write a program using function to find the product of two number 260-
23 #Having argument but no returning value 261
130 13.12. Write a program using function to find the product of two number 263
23 #Having argument but returning value

131 13.12. Write a program using function to find the product of two number 264
23 #Having no argument but returning value
132 13.12. Write a program using function to find the product of two number 265
23 #Having no argument but no returning value
133 14.12. Write a program using function to find division of two numbers 266
23
134 15.12. Write a program using function to find greatest of two numbers 267
23
135 15.12. Write a program using function to find greatest of three numbers 268
23
136 16.12. Write a program using function to check whether a number is even or odd 269
23
137 16.12. Write a program using function to find area of a circle 270
23
138 16.12. Write a program using function to find roots of a quadratic equation 271
23
139 16.12. Write a program using function to check a number is positive or negative 272
23
140 16.12. Write a program using function to find simple interest 273
23
141 16.12. Write a program using function to find smallest of three numbers 274
23
142 16.12. Write a menu driven program using function to findaddition,subtraction, 275-
23 multiplication and division 276
143 18.12. Write a menu driven program using function to find compound and simple 277-
23 interest 278
144 18.12. Write a menu driven program to find area of square,rectangle, 279-
23 triangle,circle,rhombus,paralleogram and trapizum and volume of 283
cube,cuboid,cylinder, sphere, hemisphere and cone(Using function)
145 18.12. Write a program using function to swap two numbers without using third 284
23 variable
146 18.12. Write a program using function to find prime numbers within certain range 285
23
15
147 18.12. Write a program using function to find the sum of n natural numbers 286
23
148 18.12. Write a program using function to find the factorial of a number 287
23
149 19.12. Write a program using function to find factorial of a number 288
23
150 19.12. Write a program using function to print the pattern 289
23 *
**
***
****
151 19.12. Write a program to print ther pattern 290
23 *
**
***
****
*****
152 19.12. Write a program to print the pattern(using function) 291
23 *****
****
***
**
*

153 19.12. Write a program to print the pattern 292


23 *
**
***
****
***
**
*

154 19.12. Write a program to print the pattern 293-


23 * 294
**
***
**
*
**

155 20.12. Write a program to print the pattern 295


23 *
**
* *
* *
*****

156 20.12. Write a program to print the pattern 296-


23 * 297

16
**
* *
* *
* *
* *
* *
**
*

157 20.12. Write a program to print the pattern 298-


23 * 299
**
* *
**
*
**
* *
**
*

158 20.12. Write a program to print the pattern 300


23 *
**
*#*
*##*
*****

159 20.12. Write a program to print the pattern 301


23 *
**
*#*
*##*
*#@#*

160 21.12. Write a program to print the pattern 302


23 *
***
*****
*******
161 21.12. Write a program to print the pattern 303-
23 * 304
* *
* *
* *
*****
* *
* *
* *
*

17
162 24.12. Write a program to print the pattern 305
23 1
1 2
1 23
1 234
1 2345

163 24.12. Write a program to print the pattern 306


23 *** **
* *
* *
* *
*** **
164 24.12. Write a program to print the pattern 307-
23 ***** 308
* ** *
** **
** **
*****

165 24.12. Write a program to print the pattern 309-


23 * *** ***** 310
* ** *
* * * *
* * **
* *
* * **
* * * *
* * * *
* ********

166 24.12. Write a program to print the pattern 311


23 *****
***
*

167 24.12. Write a program to print the pattern 312


23 * *
* * **
* * * ***
* * ** ****
* * *** *****

168 24.12. Write a program to print the pattern 313-


23 * * 314
** **
18
* ** ***
* *******
* ** ***
* * **
* *

169 24.12. Write a program to print the pattern 315


23 *
**
***
****
*****

170 24.12. Write a program to print the following pattern 316


23 *
*
*****
*
*

171 24.12. Write a program to print the following pattern 317


23 1
21
321
4321
54321

172 24.12. Write a program to print the following pattern 318


23 54321
4321
321
21
1

173 24.12. Write a program to print the following pattern 319


23 1
23
4 5 6320
7 8 9 10

174 24.12. Write a program to print the following pattern 320


23 1
32
654
10 9 8 7
15 14 13 12 11

175 24.12. Write a program to print the following pattern 321


23 *
*@*
19
*@#@*
*@#@#@*
*********

176 24.12. Write a program to print the following pattern 322-


23 1 323
1 1
1 2 1
1 3 3 1
1 4 6 4 1

177 24.12. Write a program to print the following pattern 324-


23 1 325
121
12321
1234321
123454321

178 26.12. Write a program to print the following pattern 324


23 1
212
32123
4321234
543212345

179 26.12. Write a program to print the patternq179 325


23 *@@@*
*@*
*

180 26.12. Write a program to print the pattern 326-


23 1 328
212
32123
4321234
*@@@@@*
*@@@*
*@*
*

181 26.12. Write a program to print the pattern 329


23
1234
2 3
3 2
4321

182 26.12. Write a program to print the pattern 330


23 456
23
1
23
20
456

183 26.12. Write a program to print the pattern 331-


23 1 332
2 3
4 5
6 7 8 9

184 26.12. Write a program to print the pattern 333-


23 1 3334
23
4 5
6789
10 11
12 13
14

185 26.12. Write a program to print the pattern 335


23 A
AB
ABC
ABCD
ABCDE

186 26.12. Write a program to print the pattern(Using function) 336


23 A
ABC
ABCDE

187 26.12. Write a program to print the pattern(Using function) 337


23 A
BA
CBA
DCBA

188 26.12. Write a program to print the pattern(Using function) 338


23 A
CB
FED
JIHG
189 26.12. Write a program to print the pattern using function 339
23 ONMLK
JIHG
FED
CB
A

190 26.12. :Write a program to print the pattern using function 340-
23 ABCBA 341
ABA
A
21
191 27.12. Write a program to print the pattern using function 342
23 CBABC
BAB
A

192 27.12. Write a program to print the pattern using function 343-
23 A 344
B1B
C121C
DCBABCD

193 27.12. Write a program to print the pattern using function 345
23 1
CBA
54321

194 27.12. Write a program to print the sum of series using function 346
23 1+2+3+4…+n

195 27.12. Write a program to print the sum of series using function 347-
23 1-2+3-4….n 348

196 27.12. Write a program to print the sum of series using function 349
23 -1+1/2-1/3…1/N

197 27.12. Write a program to print the sum of series using function 350
23 1+(1+2)+(1+2+3)+…N

198 27.12. Write a program to print the sum of series using function 351
23 X+X²+X³…xN

199 27.12. Write a program to print the sum of series using function 352
23 -1+x/2-x²/3…N

200 27.12. Write a program to print the sum of series using function 353
23 1-x/2!+x²/3!....N

201 27.12. Write a program to print the sum of series using function 354
23 1-x²/3!+x⁴/6!...N

202 27.12. Write a program to print the sum of series using function 355
23 1-x5/7!+x10/14!..N356

203 28.12. Write a program to check whether a number is 356


23 palindrome or not using function

204 28.12. Write a program to check whether a number is 357-


23 palindrome or not using function 358
205 28.12. Write a program to check whether a number is Armstrong 359
23 or not using function

22
206 28.12. Write a program to check whether a number is special or 360-
23 not using function 361
207 28.12. Write a program to check whether a number is perfect or 362
23 not using function

209 28.12. Write a program to check whether a number is magic 363-


23 number(1) or not using function 365

210 28.12. Write a program to print palindrome number between 367


23 certain range
211 28.12. Write a program to print Armstrong number between 368-
23 certain range 369
212 28.12. Write a program to print special number between certain 371
23 range

213 28.12. Write a program to print perfect number between certain 372-
23 range 373
214 28.12. Write a program to print magic naumber1 number 374-
23 between certain range 375

215 28.12. Write a program to print magic number2 between certain 376-
23 range 377
216 28.12. Write a program to print neon number between certain 378-
23 range 379
217 28.12. Write a program to check a number is a neon number or 380-
23 not 381
218 28.12. Write a program to count the number of vowels,consonants and other 382
23 character

219 9.1.24 Write a program to print the pattern using function 383-
C 384
Ca
Cat

220 9.1.24 write a program to reverse a string without changing the meaning 385
221 9.1.24 Write a program to print the pattern using function 386
C
Co
C m
C p
C u
C t
C e

222 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A 387
STRING AND REVERSE THAT STRING WITHOUT CHANGING THE
MEANING OF WORD
23
223 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A 388
STRING AND RESERVE THAT WORK AT ITS OWN PLACE
224 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO SHIFT THE RIGHT 389
HALF ELEMENT TO LEFT AND LEFT HALF ELEMENT TO RIGHT
225 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A 390-
STRING AND COUNTS THE NUMBER OF VOWELS, CONSONANT AND 391
OTHERS
226 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION THAT 392
READS A STRING AND THEN PRINTS A STRING THAT’S
CAPITALIZE EVERY OTHER LETTERS IN THE STRING

227 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE 393


INPUT A STRING AND CONVERT THE STRING TO THE
FOLLOWING PATTERN
228 9.1.24 Write a program to take input in a list method 1 394
229 9.1.24 Write a program to take input in a list method 2 395
9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A 396-
LIST AND SHIFT ALL THE NEGATIVE ELEMENT TO LEFT AND POSITIVE 397
ELEMENT TO RIGHT IN A LIST
23
0
231 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A 398-
LIST AND SEARCH THE ELEMENT USING LINEAR SEARCH 399
232 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A 400-
LIST AND SEARCH THE ELEMENT USING BINARY SEARCH TECHNIQUE 401
233 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE 402-
INPUT IN A LIST AND FIND THE SECOND GREATEST 403
ELEMENT WITHOUT SORTING
234 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO SHIFT THE RIGHT 404-
HALF ELEMENT TO LEFT AND LEFT HALF ELEMENT TO RIGHT 405
235 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE 406-
INPUT AND FIND THE SECOND SMALLEST ELEMENT 407
WITHOUT SHORTING
236 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO SORT 408-
THE ELEMENT OF A LIST USING BUBBLE SORT TECQUNIE 409

237 9.1.24 Write a program to do insertion sort 410-


411
238 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND 412-
THE ADDITION OF 2 MATRICES 413

239 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE 414-
SUBTRACTION OF 2 MATRICES 415
240 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE 416-
MULTIPLICATION OF 2 MATRIX 417
241 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A 418-
matrix AND TRANSPOSE IT 419

24
242 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO PRINT THE 420-
PRIMARY AND SECONDARY DIAGONALS OF A SQUARE MATRIX 421
243 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE SUM OF 422-
PRIMARY AND SECONDARY DIAGONALS OF THE SQUARE MATRIX 423
INDIVUSALLY
244 9.1.24 WRITE A PROGRAM IN PYTHON USING FUNCTION TO PRINT THE UPPER
HALF AND LOWER HALF OF THE SQUARE MATRIX

25
Ques1: Write a program in python to print your name 5 times
Sol:
print("Ritesh mhato ")
print("Ritesh mhato ")
print("Ritesh mhato ")
print("Ritesh mhato ")
print("Ritesh mhato ")

26
Ques2:Write a program in python to find the sum of two digits
27
Sol:
a=int(input(“Enter the First Number ”))
b=int(input(“Enter the Second Number ”))
sum=a+b
print(“Addition of two numbers is”,sum)

28
29
Ques3: Write a program to find the difference of two numbers
Sol:
a=int(input(“Enter the First Number ”))
b=int(input(“Enter the Second Number ”))
sub=a-b
print(“Difference of two numbers is”,sub)

30
31
Ques4:Write a program in python to find the multiplication of two numbers
Sol:
m=int(input(“Enter the First Number: ”))
n=int(input(“Enter the Second Number: ”))
mul=m*n
print(“Multiplication of %d and %d is %d”%(m,n,mull))

32
33
Ques5: Write a program in python to find the division of two numbers
Sol:
m=int(input(“Enter the First Number: ”))
n=int(input(“Enter the Second Number: ”))
if (n==0):
print(“Cannot divide by zero”)
else:
div=m/n
print(“Division of %d by %d is %f”%(m,n,div))

34
35
.
Ques6: Write a program in python to find the greatest of two numbers
Sol:
a=int(input(“Enter the First Number: ”))
b=int(input(“Enter the Second Number: ”))
if a>b:
print(“%d is the greatest number”%(a))
else:
print(“%d is the greatest number”%(b))

36
37
Ques7:Write a program in python to find the greatest of three numbers
Sol:
m=int(input(“Enter the First Number “))
n=int(input(“Enter the Second Number ”))
p=int(input(“Enter the Third Number ”))
if m>n and m>p:
print(m,“is the greatest number”)
elif n>p:
print(n,“is the greatest number”)
else:
print(p,“is the greatest number”)

38
39
Ques8:Write a program in python to check whether a Number is even or odd
Sol:
n=int(input(“Enter a Number: ”))
if n% 2==0:
print(“%d is an even number”%(n))
else:
print(“%d is an odd number”%(n))

40
41
Ques9:Write a program in python to find the area of a circle
Sol:
import math
r=int(input(“Enter the radius of a circle ”))
area=math.pi*math.pow(r,2)
print(“Area of circle is”,area)

42
43
Ques10:Write a program in python to find the roots of a quadratic equation
Sol:
import math
a=int(input(“Enter the value of a: ”))
b=int(input(“Enter the value of b: ”))
c=int(input(“Enter the value of c: ”))
if a==0:
print(“This is not a Quadratic Equation”)
else:
d=b*b-4*a*c
if d<0:
print(“Roots are imaginary”)
elif d==0:
x=-b/(2*a)
print(“Roots of the Equation is”,x)
else:
x1=(-b+math.sqrt(d))/(2*a)
x2=(-b-math.sqrt(d))/(2*a)
print(“Roots of the equation are”,x1,x2)

44
45
Ques11:Write a program in python to find whether a Number is positive or negative
Sol:
n=int(input(“Enter the Number ”))
if n>0:
print(n,“is a positive number”)
elif n<0:
print(n,“is a negative number”)
else:
print(“You have entered zero”)

46
47
Ques12:Write a program in python to find the simple interest
Sol:
p=float(input(“Enter the Principal amount ”))
r=float(input(“Enter the Rate of Interest ”))
t=float(input(“Enter the Time ”))
SI=(p*r*t)/100
print(“Simple Interest is”,SI)

48
49
Ques13:Write a program in python to find the smallest of three numbers
Sol:
a=int(input(“Enter the First Number ”))
b=int(input(“Enter the Second Number ”))
c=int(input(“Enter the Third Number ”))
if a<b and a<c:
print(a,“is the smallest number”)
else b<c:
print(b,“is the smallest number”)
else:
print(c,“is the smallest number”)

50
51
Ques14:Write a program in python to
findtheaddition,subtraction,multiplication,division of two numbers
Sol:
print(“Menu of the Program”)
print(‘‘‘1.Addition
2.Subtraction
3.Multiplication
4.Division’’’)
ch=int(input(“Enter your choice “))
a=int(input(“Enter the First Number “))
b=int(input(“Enter the Second Number “))
if ch==1:
sum=a+b
print(“Sum of %d and %d is %d”%(a,b,sum))
elsech==2:
sub=a-b
print(“Subtraction of %d and %d is %d”%(a,b,sub))
elsech==4:
if b==0:
print(“Cannot divide by zero”)
else:
div=a/b
print(“Division of %d by %d is %f”%(a,b,div))
elifch==3:
mul=a*b
print(“Multiplication of %d and %d is %d”%(a,b,mul))
else:
print(“Wrong choice”)

52
53
Ques15:Write a menu driven program in python to find simple interest and compound
interest
Sol:
print(“Menu of the Program”)
print(‘‘‘1.Simple Interest
2.Compound Interest’’’)
ch=int(input(“Enter your choice ”))
p=float(input(“Enter Principal Amount ”))
r=float(input(“Enter the Rate of Interest ”))
t=float(input(“Enter the Time ”))
if ch==1:
SI=(p*r*t)/100
print(“Simple Interest is”,SI)
elifch==2:
CI=p*(1+r/100)**t
print(“Compound Interest is”,CI)
else:
print(“Wrong Choice”)

54
55
Ques16:Write a menu driven program in python to find area of square,rectangle,
circle, trapizum,rhombus,triangle and volume of
cube,cuboid,cylinder,sphere,hemisphere,cone
Sol:
import math
while True:
print(“Menu of the Program”)
print(‘‘‘1.Area
2.Volume’’’)
ch=int(input(“Enter your Choice:”))
ifch==1:
print(‘‘‘1.Area of Circle
2.Area of Rectangle
3.Area of Square
4.Area of Triangle
5.Area of Parallelogram
6.Area of Trapezium’’’)
c=int(input(“Enter your Choice:”))
if c==1:
r=int(input(“Enter radius of the circle:”))
area=math.pi*math.pow(r,2)
print(“Area of Circle=”,area)
elif c==2:
l=int(input(“Enter length of Rectangle:”))
b=int(input(“Enter breadth of Rectangle:”))
area=l*b
print(“Area of Rectangle=”,area)
elif c==3:
s=int(input(“Enter side of the square:”))
area=s*s
print(“Area of Square=”,area)
elif c==4:

56
l=int(input(“Enter 1st side of the triangle:”))
b=int(input(“Enter 2nd side of the Triangle:”))
h=int(input(“Enter 3rd side of the Triangle:”))
s=(l+b+h)/2
area=(s*(s-l)*(s-b)*(s-h))**1/2
print(“Area of Triangle=”,area)
elif c==5:
h=int(input(“Enter Height of Parallelogram:”))
b=int(input(“Enter Base of Parallelogram:”))
area=b*h
elif c==6:
s=int(input(“Enter side1 of the trapezium:”))
b=int(input(“Enter side2 of the trapezium:”))
d=int(input(“Enter side3 of the trapezium:”))
area=((s+b)*d)/2
print(“Area of Trapezium=”,area)
else:
print(“WRONG CHOICE”)
elifch==2:
print(‘‘‘1.Volume of Cube
2.Volume of Cuboid
3.Volume of Cylinder
4.Volume of Sphere
5.Volume of Hemisphere
6.Volume of Cone’’’)
c=int(input(“Enter your Choice:”))
if c==1:
S=int(input(“Enter side of Cube:”))
v=s*s*s
print(“Volume of a Cube=”,v)
elif c==2:
l=int(input(“Enter length of cuboid:”))
57
b=int(input(“Enter Breadth of cuboid:”))
h=int(input(“Enter Height of cuboid:”))
v=l*b*h
print(“Volume of cuboid=”,v)
elif c==3:
r=int(input(“Enter radius of Cylinder:”))
h=int(input(“Enter height of Cylinder:”))
v=math.pi*math.pow(r,2)*h
print(“Volume of Cylinder=”,v)
elif c==5:
r=int(input(“Enter radius of Hemisphere:”))
v=2*(math.pi*r*r*r)/3
print(“Volume of Hemisphere=”,v)
elif c==4:
r=int(input(“Enter radius of sphere:”))
v=4*(math.pi*r*r*r)/3
print(“Volume of Sphere=”,v)
elif c==6:
r=int(input(“Enter radius of cone:”))
h=int(input(“Enter height of cone:”))
v=(math.pi*r*r*h)/3
print(“Volume of Cone=”,v)
else:
print(“WRONG CHOICE”)
else:
print(“WRONG CHOICE”)
print(“Do you want to continue?(y/n)”)
c=input()
if c==’y’ or c==’Y’:
continue
else:
break
58
59
60
Ques17:Write a program in python to find swapping of two numbers
Sol:
m=int(input(“Enter the First Number: ”))
n=int(input(“Enter the Second Number: ”))
print(“Before Swapping”)
print(“M =”,m)
print(“N =”,n)
temp=m
m=n
n=temp
print(“After Swapping”)
print(“M =”,m)
print(“N =”,n)

61
62
Ques18:Write a program in python to swap two numbers without using third variable
Sol:
m=int(input(“Enter the First Number: ”))
n=int(input(“Enter the Second Number: ”))
print(“Before Swapping”)
print(“M =”,m)
print(“N =”,n)
m=m+n
n=m-n
m=m-n
print(“After Swapping”)
print(“M =”,m)
print(“N =”,n)

63
64
Ques19:Write a program in python to check whether a Number is prime Number or
not
Sol:
n=int(input(“Enter the number ”))
count=0
for i in range (1,n//2+1):
if n% i==0:
count+=1
if count==1:
print(“%d is a prime number”%(n))
else:
print(“%d is not a prime number”%(n))

65
66
Ques20:Write a program in python to Count and display prime number between
certain range
Sol:
n=int(input(“Enter the number “))
Count=0
for i in range (1,n//2+1):
if n% i==0:
Count+=1
if Count==1:
print(“%d is a prime number”%(n))
else:
print(“%d is not a prime number”%(n))

67
68
Ques21:Write a program in python to find the sum of n natural numbers
Sol:
n=int(input(“Enter the value of n :”))
i=1
Sum=0
while i<=n:
Sum+=i
i+=1
print(“Sum of ”,n,“natural number :”,sum)

69
70
Ques22:Write a program in python to find the sum of even and odd number within a
certain range
Sol:
m=int(input(“Enter the initial range value “))
p=int(input(“Enter the final range value”))
sodd=seven=0
while m<=p:
if m%2==0:
seven+=m
else :
sodd+=m
m+=1
print(“Sum of even number between certain range=”,seven)
print(“Sum of odd number between certain range=”,sodd)

71
72
Ques23:Write a program in python to find the factorial of a number
Sol:
n=int(input(“Enter the value of n:”))
i=1
fact=1
while i<=n:
fact*=i
i+=1
print(“Factorial of %d is %d ”%(n,fact))

73
74
Ques24:Write a program in python to find fibonacci series
Sol:
n=int(input(“Enter the number of rows “))
i=1
while i<=n:
j=1
while j<=i:
print(“*”,end=“ ”)
j+=1
print()
i+=1

75
76
Ques25:Write a program in python to print the following pattern
*
**
***
Sol:
n=int(input(“Enter the number of rows “))
i=1
while i<=n:
j=1
while j<=i:
print(“*”,end=“ ”)
J+=1
Print( )
I+=1

77
78
Ques26:Write a program in python to print the following pattern
*****
****
***
**
*
Sol:
n=int(input(“Enter the number of rows:”))
i=1
while i<=n:
j=n-i+1
while j>=1:
print(“*”,end=“ ”)
j-=1
print()
i+=1

79
80
Ques27:Write a program in python to print the following pattern
*
**
***
****
Sol:
n=int(input(“Enter the number of rows ”))
i=1
while i<=n:
j=1
while j<=n-i+1:
print(“”,end=“ ”)
j+=1
k=1
while k<=i:
print(“*”,end=“ ”)
k+=1
print()
i+=1

81
82
Ques28:Write a program in python to print the following pattern
*
**
***
****
Sol:
n=int(input(“Enter the number of rows “))
for iin range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(“*”,end=“ ”)
print()

83
84
Ques29:Write a program in python to print the following pattern
*****
****
***
**
*
Sol:
n=int(input(“Enter the number of rows “))
for i in range(1,n+1):
for j in range(1,i+1):
print(“ “,end=“”)
for k in range(n-i+1):
print(“*”,end=“ ”)
print()

85
86
Ques30:Write a program in python to print the following pattern
*
**
***
****
*****
****
***
**
*
Sol:
n=int(input(“Enter the number of rows “))
for iin range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(“*”,end=“ ”)
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(“*”,end=“ ”)
print()

87
88
Ques31:Write a program in python to print the following pattern
*
**
***
****
*****
****
***
**
*
**
***
****

Sol:
n=int(input(“Enter the number of rows ”))
for i in range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(“*”,end=“ ”)
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(“*”,end=“ ”)
print()
for i in range(n-2,0,-1):
for j in range(1,i+2):
print(“”,end=“ ”)
for k in range(1,n-i+1):
89
print(“*”,end=“ ”)
print()

90
91
Ques32:Write a program in python to print the following pattern
*
**
* *
* *
*****
Sol:
n=int(input(“Enter the number of rows “))
for iin range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==I or i==n:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()

92
93
Ques33:Write a program in python to print the following pattern
*
**
* *
* *
* *
* *
* *
**
*
Sol:
n=int(input(“Enter the number of rows “))
for i in range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for iin range(n-1,0,-1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
Print(“ ”,end=“ ”)
print()

94
95
Ques34:Write a program in python to print the following pattern
*
**
* *
**
*
**
* *
**
*
Sol:
n=int(input(“Enter the number of rows “))
for iin range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for i in range(2,n+1):
for j in range(1,n-i+2):
96
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for iin range(n-1,0,-1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if k==1 or k==i:
print(“*”,end=“ ”)
else:
print(“ “,end=“ ”)
print()

97
98
Ques35:Write a program in python to print the following pattern
*
**
*#*
*##*
*****
Sol:
n=int(input(“Enter the value of n:”))
for i in range(1,n+1):
for j in range(1,n-i+1):
print(“ ”,end=“”)
for k in range(1,i+1):
if(k==1 or k==I or i==n):
print(“*”,end=“ ”)
else:
print(“#”,end=“ ”)
print()

99
100
Ques36:Write a program in python to print the following pattern
*
***
*****
*******
Sol:
n=int(input(“Enter the value of n:”))
for i in range(1,n+1):
for j in range(1,n-i+2):
print(“ ”,end=“ ”)
for k in range(1,i*2):
print(“*”,end=“ ”)
print()

101
102
Ques37:Write a program in python to print the following pattern
*
**
*#*
*##*
*#@#*
Sol:
n=int(input(“Enter the value of n:”))
for iin range(1,n+1):
for j in range(1,n-i+1):
print(“ “,end=“”)
for k in range(1,i+1):
if(k==1 or k==i):
print(“*”,end=“ ”)
elif(k==2 or k==i-1):
print(“#”,end=“ ”)
else:
print(“@”,end=“ ”)
print()

103
104
Ques38:Write a program in python to print the following pattern
*
* *
* *
* *
* *
* *
* *
* *
*********
* *
* *
* *
* *
* *
* *
* *
*
Sol:
n=int(input(“Enter the number of rows: “))
for i in range (1,n+1):
for j in range(1,n-i+1):
print(“ ”,end=“ ”)
for k in range (1,i*2):
if k==1 or k==i*2-1:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for iin range (n-1,0,-1):
for j in range(1,n-i+1):
if i==1:
105
break
print(“ ”,end=“ ”)
for k in range (1,i*2):
if(i!=1):
if k==1 or k==i*2-1:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
else:
for m in range(1,n*2):
print(“*”,end=“ ”)
print()
for i in range (2,n+1):
for j in range(1,n-i+1):
print(“ ”,end=“ ”)
for k in range (1,i*2):
if k==1 or k==i*2-1:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()
for i in range (n-1,0,-1):
for j in range(1,n-i+1):
Print(“ ”,end=“ ”)
for k in range (1,i*2):
if k==1 or k==i*2-1:
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()

106
107
Ques39:Write a program in python to print the following pattern
*****
* *
* *
* *
*****
Sol:
n=int(input(“Enter the value of n:”))
for i in range(1,n+1):
for j in range(1,n+1):
if(j==1 or j==n or i==1 or i==n):
print(“*”,end=“ ”)
else:
print(“ ”,end=“ ”)
print()

108
109
Ques40:Write a program in python to print the following pattern
*****
* ** *
** **
** **
*****
Sol:
n=int(input(“Enter the number of rows ”))
for i in range(1,n+1):
for j in range(1,n+1):
if i==1 or i==n:
Print(“*”,end=“ ”)
elif j==1:
print(“*”,end=“”)
else:
print(“”,end=“”)
if i==1 or i==n:
print(“”,end=“”)
else:
for k in range(2,n-i+1):
print(“”,end=“ ”)
for l in range(1,i+1):
if l==n-1:
print(“*”,end=“”)
elif l==1 or l==i:
print(“*”,end=“ ”)
else:
Print(“ ”,end=“ ”)
for m in range(2,n-i):
print(“”,end=“ ”)
print(“*”,end=“”)
print()
110
111
112
Ques41:Write a program in python to print the following pattern
*********
* * * *
* * * *
** * *
* *
** * *
* * * *
* * * *
*********
Sol:
n=int(input("Enter the range:"))
for i in range(1,n+1):
for j in range(1,n-i+2):
if(j==1 or j==n-i+1 or i==1):
print("*",end=" ")
else:
print(" ",end=" ")
for m in range(2,i*2-1):
print(" ",end=" ")
for k in range(n-i+2,1,-1):
if(k==n-i+2 or k==2 or i==1):
if(k<=n):
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
if(j==1 or j==n-i+1 or i==1):
print("*",end=" ")
else:
113
print(" ",end=" ")
for m in range(2,i*2-1):
print(" ",end=" ")
for k in range(1,n-i+2):
if(k==n-i+1 or k==1 or i==1):
if(k<n):
print("*",end=" ")
else:
print(" ",end=" ")
print()

114
115
Ques42:Write a program in python to print the following pattern
*************
***********
*********
*******
*****
***
*
Sol:
n=int(input(“Enter the number of rows ”))
for i in range(n,0,-1):
for j in range(n*2,i*2-1,-1):
print(“”,end=“ ”)
for k in range(1,i*2):
print(“*”,end=“ ”)
print()

116
117
Ques43:Write a program in python to print the following pattern
* *
** **
*** ***
**** ****
***** *****
****** ******
Sol:
n=int(input(“Enter the number of rows ”))
for i in range(n,0,-1):
for j in range(0,n-i+1):
print(“*”,end=“ ”)
for k in range(1,i*2):
print(“ ”,end=“ ”)
for m in range(0,n-i+1):
print(“*”,end=“ ”)
print()

118
119
Ques44:Write a program in python to print the pattern
*
*
*****
*
*
Sol:
n=int(input(“Enter the number of rows ”))
for i in range(1,n+1):
for j in range(1,n+1):
if(j==(n+1)//2) or (i==(n+1)//2):
print(“*”,end=“ ”)
else:
print(“ “,end=“ ”)
print()

120
121
Ques45:Write a program in python to print the following pattern
1
12
123
1234
12345
n=int(input(“Enter the number of rows ”))
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end=“ ”)
print()

122
123
Ques46:Write a program in python to print the following pattern
1
21
321
4321
54321
654321
n=int(input(“Enter the number of rows ”))
for i in range(1,n+1):
k=i
for j in range(1,i+1):
print(k,end=“ ”)
k-=1
print()

124
125
Ques47:Write a program in python to print the following pattern
54321
4321
321
21
1
n=int(input(“Enter the number of rows ”))
for i in range(n,0,-1):
k=i
for j in range(1,i+1):
print(k,end=“ ”)
k-=1
print()

126
127
Ques48:Write a program in python to print the following pattern
54321
5432
5 4 3 NAS Nlkn JA I NPV N JFF
54
5
n=int(input(“Enter the number of rows ”))
for iin range(n,0,-1):
k=n
for j in range(1,i+1):
print(k,end=“ ”)
k-=1
print()

128
129
Ques49:Write a program in python to print the following pattern
1
23
456
7 8 9 10
n=int(input(“Enter the number of rows ”))
l=1
for iin range(1,n+1):
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(l,end=“ ”)
l+=1
print()

130
131
Ques50:Write a program in python to print the following pattern
1
32
654
10 9 8 7
15 14 13 12 11
n=int(input(“Enter the number of lines:”))
p=1
for i in range(1,n+1):
p=p+i
for j in range(1,n-i+2):
print(“ ”,end=“”)
for k in range(1,i+1):
print((p-k),end=“ ”)
print()

132
133
Ques51:Write a program in python to print the following pattern
*
*@*
*@#@*
*@#@#@*
*********
n=int(input(“Enter the number of rows:”))
for i in range(1,n+1):
for j in range(1,n-i+1):
print(“ ”,end=“ ”)
for k in range(1,i*2):
if(k==1 or k==i*2-1)or i==n:
print(“*”,end=“ ”)
elif(k==2 or k==i*2-2):
print(“@”,end=“ ”)
elif(k==3 or k==i*2-3):
print(“#”,end=“ ”)
else:
print(“@”,end=“ ”)
print()

134
135
Ques52:Write a program in python to print the following pattern
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
n=int(input(“Enter the range:”))
for i in range(1,n+1):
for j in range(1,n-i+2):
print(“ ”,end=” “)
p=1
for k in range(1,i+1):
print(“ ”,p,sep=” “,end=“ ”)
p=p*(i-k)//k
print()

136
137
Ques53:Write a program in python to print the following pattern
1
121
12321
1234321
123454321
Sol:
n=int(input(“Enter the number of lines:”))
for iin range(1,n+1):
for j in range(2*n,2*i-1,-1):
print(“ ”,end=“”)
for k in range(1,i+1):
print(k,end=“ ”)
for l in range(i-1,0,-1):
print(l,end=“ ”)

138
139
print()

140
Ques54:Write a program in python to print the following pattern
1
212
32123
4321234
*@@@*
*@*
*
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
for j in range(1,n-i+1):
print(“ ”,end=“ ”)
for k in range(I,0,-1):
print(k,end=“ ”)
for l in range(2,i+1):
print(l,end=“ ”)
print()
n=n-1
for iin range(n,0,-1):
for j in range(1,n-i+2):
print(“ ”,end=“ ”)
for k in range(1,i*2):
if(k==1 or k==i*2-1):
print(“*”,end=“ ”)
else:
print(“@”,end=“ ”)
print()

141
142
Ques55:Write a program in python to print the following pattern
12345
4 4
3 3
2 2
54321
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
for j in range(1,n+1):
if(i==1):
print(j,end=“ ”)
elif(i==n):
print(n-j+1,end=“ ”)
elif(j==1):
print(i,end=“ ”)
elif(j==n):
print(n-i+1,end=“ ”)
else:
print(“ ”,end=“ ”)
print()

143
144
Ques56:Write a program in python to print the following pattern
7 8 9 10
456
23
1
23
456
7 8 9 10
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(n,0,-1):
for j in range(1,n-i+2):
print(“ ”,end=“”)
for k in range(i*(i+1)//2-I,i*(i+1)//2):
print(k+1,end=“ ”)
print()
for i in range(2,n+1):
for j in range(1,n-i+2):
print(“ ”,end=“”)
for k in range(i*(i+1)//2-I,i*(i+1)//2):
print(k+1,end=“ ”)
print()

145
146
Ques57:Write a program in python to print the following pattern
1
2 3
4 5
6 7 8 9
Sol:
n=int(input(“Enter the number of lines:”))
p=1
for i in range(1,n):
for j in range(1,n-i+2):
print(“ ”,end=“ ”)
for k in range(1,i*2):
if (k==1 or k==i*2-1) or (i==1):
print(p,end=“ ”)
p=p+1
else:
print(“ ”,end=“ ”)
print()
for iin range(1,n*2+1):
if (i%2==0):
print(p,end=“ ”)
p=p+1
else:
print(“ ”,end=“ ”)
print()

147
148
Ques58:Write a program in python to print the following pattern
1
2 3
4 5
6789
10 11
12 13
14
Sol:
n=int(input(“Enter the number of rows:”))
m=1
for i in range(1,n+1):
for j in range(1,n-i+1):
print(“”,end=“ ”)
for k in range(1,i+1):
if(k==1 or k==I or i==n):
print(m,end=“ ”)
m+=1
else:
print(“ ”,end=“ ”)
print()
for i in range(n-1,0,-1):
for j in range(1,n-i):
print(“”,end=“ ”)
for k in range(1,i+1):
if(k==1 or k==i):
print(m,end=“ ”)
m+=1
else:
print(“ ”,end=“ ”)
print()

149
150
Ques59:Write a program in python to print the following pattern
A
AB
ABC
ABCD
ABCDE
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65
for j in range(1,i+1):
print(chr(ch),end=“ ”)
ch+=1
print()

151
152
Ques60:Write a program in python to print the following pattern
A
AB
ABC
ABCD
ABCDE
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65
for j in range(1,n-i+1):
print(“”,end=“ ”)
for k in range(1,i+1):
print(chr(ch),end=“ ”)
ch+=1
print()

153
154
Ques61:Write a program in python to print the following pattern
A
BA
CBA
DCBA
EDCBA
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65+i-1
for j in range(1,n-i+1):
print(“”,end=“ ”)
for k in range(1,i+1):
print(chr(ch),end=“ ”)
ch-=1
print()

155
156
Ques62:Write a program in python to print the following pattern
A
CB
FED
JIHG
ONMLK
Sol:
n=int(input(“Enter the number of lines:”))
ch=65
for i in range(1,n+1):
ch=ch+i
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
print(chr(ch-k),end=“ ”)
print()

157
158
Ques63:Write a program in python to print the following pattern
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65
for j in range(2*(n-i)+1):
Print(“”,end=“ ”)
for k in range(1,i*2):
print(chr(ch),end=“ ”)
ch+=1
print()

159
160
Ques64:Write a program in python to print the following pattern
ONMLK
JIHG
FED
CB
A
Sol:
n=int(input(“Enter the number of lines:”))
ch=65+n*(n+1)//2-1
for i in range(1,n+1):
for j in range(1,i+1):
Print(“”,end=“ ”)
for k in range(n,i-1,-1):
print(chr(ch),end=“ ”)
ch-=1
print()

161
162
Ques65:Write a program in python to print the following pattern
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
Sol:
n=int(input(“Enter the number of lines:”))
for iin range(1,n+1):
ch=65
for j in range(1,i*2):
print(“”,end=“ ”)
for k in range(1,(n-i+1)*2):
if (k<=(n-i+1)):
print(chr(ch),end=“ ”)
ch+=1
else:
ch-=1
print(chr(ch-1),end=“ ”)
print()

163
164
Ques66:Write a program in python to print the following pattern
EDCBABCDE
DCBABCD
CBABC
BAB
A
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65+n-i
for j in range(1,i*2):
print(“”,end=“ ”)
for k in range(1,(n-i+1)*2):
if (k<=(n-i+1)):
print(chr(ch),end=“ ”)
ch-=1
else:
ch+=1
print(chr(ch+1),end=“ ”)
print()

165
166
Ques67:Write a program in python to print the following pattern
A
B1B
C121C
D12321D
EDCBABCDE
Sol:
n=int(input(“Enter the number of lines:”))
ch=65
for iin range(1,n+1):
c=1
for j in range(1,n*2-i*2+1):
print(“”,end=“ ”)
for k in range(1,i*2):
if (i==n):
if (k<=n):
print(chr(ch),end=“ ”)
ch-=1
else:
ch+=1
print(chr(ch+1),end=“ ”)
elif (k==1 or k==i*2-1):
print(chr(ch),end=“ ”)
elif (k<=i):
print(c,end=“ ”)
c+=1
else:
c-=1
print((c-1),end=“ ”)
ch+=1
print()

167
168
Ques68:Write a program in python to print the following pattern
1
AB
123
ABCD
Sol:
n=int(input(“Enter the number of lines:”))
for i in range(1,n+1):
ch=65
for j in range(1,n-i+2):
print(“”,end=“ ”)
for k in range(1,i+1):
if (i%2!=0):
print(k,end=“ ”)
else:
print(chr(ch),end=“ ”)
ch+=1
print()

169
170
Ques69:Write a program in python to print the following pattern
1
CBA
54321
GFEDCBA
Sol:
n=int(input(“Enter the number of lines:”))
foriin range(1,n+1):
ch=65+(2*(i-1))
for j in range(1,n*2-i*2+1):
print(“”,end=“ ”)
for k in range(i*2-1,0,-1):
if (i%2!=0):
print(k,end=“ ”)
else:
print(chr(ch),end=“ ”)
ch-=1
print()

171
172
Ques70:Write a program in python to print the sum of series
1+2+3+4……+N
Sol:
n=int(input(“Enter the number of terms:”))
sum=0
for i in range(1,n+1):
sum+=i
print(“Sum of the series is”,sum)

173
174
Ques71:Write a program in python to print the sum of series
1-2+3-4……N
Sol:
n=int(input(“Enter the number of terms:”))
sum=0
for i in range(1,n+1):
sum+=(-1)**(i+1)*i
print(“Sum of the series is”,sum)

175
176
Ques72:Write a program in python to print the the sum of series
-1+1/2-1/3+……N
Sol:
n=int(input(“Enter the number of terms:”))
sum=0
for i in range(1,n+1):
sum+=(-1)**(i)*(1/i)
print(“Sum of the series is”,sum)

177
178
Ques73:Write a program in python to print the sum of series
1+(1+2)+(1+2+3)….N
Sol:
n=int(input(“Enter the range:”))
sum=0
fori in range(1,n+1):
for j in range(1,i+1):
sum+=j
print(“Sum of the series is”,sum)

179
180
Ques74:Write a program in python to print the sum of series
x+x²+x³+…….
sum=0
x=int(input(“Enter the value of x:”))
n=int(input(“Enter the number of terms:”))
for i in range(1,n+1):
sum+=(x)**(i)
print(“Sum of the series is”,sum)

181
182
Ques75:Write a program in python to print the sum of series
1-x/2+x³/3-x⁴/4……
Sol:
sum=0
x=int(input(“Enter the value of x:”))
n=int(input(“Enter the value of n:”))
for i in range(1,n+1):
sum+=(-1)**(i+1)*(x**(i-1))/i
print(“Sum of the series is”,sum)

183
184
Ques76:Write a program in python to print the sum of series
1-x/2!+x²/3!.....
Sol:
n=int(input(“Enter the number of terms:”))
x=int(input(“Enter the value of x:”))
sum=0
for iin range(n):
fact=1
for j in range(1,i+2):
fact*=j
sum+=((-1)**i)*(x**i)/fact
print(“Sum of the series is”,sum)

185
186
Quse77:Write a program in python to print the sum of series
1-x²/3!+x⁴/6!......N
Sol:
n=int(input(“Enter the value of n”))
x=int(input(“Enter the value of x”))
sum=1
for i in range(1,n+1):
fact=1
for j in range(1,3*(i-1)+1):
fact=fact*j
sum+=(-1)**(i+1)*x**(2*(i-1))/fact
print(“Sum of the series is”,sum)

187
188
Ques78:Write a program in python to print the sum of series
1-X5/7!+X10/14!....N
Sol:
n=int(input(“Enter the number of terms:”))
x=int(input(“Enter the value of x:”))
sum=1
for i in range(1,n+1):
fact=1
for j in range(1,7*(i-1)+1):
fact*=j
sum+=(-1)**(i+1)*x**5*(i-1)/fact
print(“Sum of the series is”,sum)

189
190
Ques79:Write a program to check whether a Number is a palindrome or not
Sol:
n=int(input(“Enter a number:”))
p=n
sum=0
while p!=0:
r=p%10
sum=sum*10+r
p//=10
if sum==n:
print(“%d is a palindrome number”%(n))
else:
print(“%d is not a palindrome number”%(n))

191
192
Ques80:Write a program in python to check whether a Number is armstrong or not
Sol:
n=int(input(“Enter a number:”))
p=n
sum=0
while p!=0:
r=p%10
sum+=r**3
p//=10
if sum==n:
print(“%d is a armstrong number”%(n))
else:
print(“%d is not a armstrong number”%(n))

193
194
Ques81:Write a python program to print the series
-5,10,-15,20…N
Sol:
n=int(input(“Enter the number of terms:”))
for I in range(1,n+1):
p=((-1)**i)*(5*i)
print(p,end=”,”)

195
196
Ques82:Write a program in python to print the series
2,9,28,65…N
Sol:
n=int(input(“Enter the number of terms:”))
for i in range(1,n+1):
print((i**3)+1,end=”,”)

197
Ques83:Write a python program to print the series
0,6,24,60…N
Sol:
n=int(input(“Enter the number of terms:”))
for i in range(1,n+1):
print((i**3)-i,end=”,”)

198
Ques84:Write a program in python to print the series
-6x³/5!+24x5/7!-60x7/9!....N
Sol:
n=int(input(“Enter the number of terms:”))
x=int(input(“Enter the value of x:”))
sum=0
c=1
for i in range(2,n+2):
fact=1
for j in range(1,2*i+2):
fact*=j
sum+=((-1)**(i+1))*((i**3)-i)*(x**(i+c))/fact
c+=1
print(“Sum of series is “,sum)

199
Ques85:Write a program in python to check a Number is a special Number or not
Sol:
n=int(input(“Enter a number:”))
p=n
sum=0
while p!=0:
fact=1
r=p%10
for i in range(1,r+1):
fact*=i
sum+=fact
p//=10
if sum==n:
print(“%d is a special number”%(n))
else:
print(“%d is not a special number”%(n))

200
Ques86:Write a program in python to check a Number is a perfect Number or not
Sol:
n=int(input(“Enter a number:”))
sum=0
for i in range(1,n):
if(n%i==0):
sum+=i
if sum==n:
print(“%d is a perfect number”%(n))
else:
print(“%d is not a perfect number”%(n))

201
Ques87:Write a program to check whether a number is a magic Numbers(1) or not
[1458=1+4+5+8=18*81=1458]
Sol:
n=int(input(“Enter a number:”))
p=n
s=0
r=0
while(p!=0):
d=p%10
s+=d
p//=10
m=s
while(m!=0):
k=m%10
r=r*10+k
m//=10
if((s*r)==n):
print(“%d is a magic number”%(n))
else:
print(“%d is not a magic number “%(n))

202
203
Ques88:Write a program in python to check whether a number is a magic Number(2)
or not. [55=5+5=10=1+0=1]
Sol:
n=int(input(“Enter a number:”))
p=n
while p>=10:
sum=0
while p!=0:
r=p%10
sum+=r
p//=10
p=sum
if sum==1:
print(“%d is a magic number”%(n))
else:
print(“%d is not a magic number”%(n))

204
Ques89:Write a python program to check whether a Number is a neon number or not
Sol:
import math
n=int(input(“Enter a number:”))
sum=0
p=math.pow(n,2)
while p!=0:
d=p%10
sum+=d
p//=10
if sum==n:
print(“%d is a neon number”%(n))
else:
print(“%d is not a neon number”%(n))

205
Ques90:Write a python program to Count and print palindrome Number within certain
range
Sol:
m=int(input(“Enter the first number:”))
n=int(input(“Enter the last number:”))
count=0
print(“Palindrome numbers between %d and %d are”%(m,n))
for I in range(m,n+1):
p=i
sum=0
while p!=0:
r=p%10
sum=sum*10+r
p//=10
if sum==i:
count+=1
print(I,end=”,”)
print()
print(“Total palindrome numbers between %d amd %d is %d “%(m,n,count))

206
Ques91:Write a python program to Count and print armstrong Number within certain
range
Sol:
m=int(input(“Enter the first number:”))
n=int(input(“Enter the last number:”))
count=0
print(“Armstrong numbers between %d amd %d are”%(m,n))
for i in range(m,n+1):
c=0
p=i
sum=0
while p!=0:
p//=10
c+=1
q=i
while q!=0:
r=q%10
sum+=r**c
q//=10
if sum==i:
count+=1
print(i,end=”,”)
print()
print(“Total Armstrong numbers between %d amd %d is %d “%(m,n,count))

207
208
Ques92:Write a python program to Count and print special Number within certain
range
Sol:
m=int(input(“Enter the first number:”))
n=int(input(“Enter the last number:”))
count=0
print(“Special numbers between %d and %d are”%(m,n))
for iin range(m,n+1):
p=i
sum=0
while p!=0:
fact=1
r=p%10
for j in range(1,r+1):
fact*=j
sum+=fact
p//=10
if sum==i:
count+=1
print(i,end=”,”)
print()
print(“Total special numbers between %d and %d is %d “%(m,n,count))

209
Ques93:Write a python program to Count and print perfect Number within certain
range
Sol:
m=int(input(“Enter the first number:”))
n=int(input(“Enter the last number:”))
count=0
print(“Perfect numbers between %d and %d are”%(m,n))
for i in range(m,n+1):
sum=0
for j in range(1,i):
if(i%j==0):
sum+=j
if sum==i:
count+=1
print(i,end=”,”)
print()
print(“Total perfect numbers between %d and %d are %d “%(m,n,count))

210
Ques94:Write a python program to Count and print magic Numbers (1)Number within
certain range
Sol:
a=int(input(“Enter the first number:”))
b=int(input(“Enter the last number:”))
count=0
print(“Magic numbers between %d and %d are”%(a,b))
for iin range(a,b+1):
o=i
s=0
r=0
while(p!=0):
d=p%10
s+=d
p//=10
m=s
while(m!=0):
k=m%10
r=r*10+k
m//=10
if((s*r)==i):
count+=1
print(i,end=”,”)
print()
print(“Total magic numbers between %d and %d are %d”%(a,b,count))

211
212
Ques95:Write a python program to Count and print magic Number(2) within certain
range
Sol:
a=int(input(“Enter the first number:”))
b=int(input(“Enter the last number:”))
count=0
print(“Magic numbers between %d and %d are”%(a,b))
for i in range(a,b+1):
p=i
while p>=10:
s=0
while(p!=0):
d=p%10
s+=d
p//=10
p=s
if s==1:
count+=1
print(i,end=”,”)
print()
print(“Total magic numbers between %d and %d are %d”%(a,b,count))

213
Ques96:Write a python program to Count and print neon number within certain range
Sol:
import math
m=int(input(“Enter the first number:”))
n=int(input(“Enter the last number:”))
count=0
print(“Neon numbers between %d and %d are”%(m,n))
for i in range(m,n+1):
sum=0
p=math.pow(I,2)
while(p!=0):
d=p%10
sum+=d
p//=10
if sum==i:
count+=1
print(i,end=”,”)
print()
print(“Total neon numbers between %d and %d are %d”%(m,n,count))

214
Ques97:Write a python program to Count the Number of vowels and consonants and
other character
Sol:
str=input("ENTER A STRING")
vowel="aeiouAEIOU"
consta="bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
v=c=ot=0
for i in range(len(str)):
if str[i] in vowel:
v+=1
elifstr[i] in consta:
c+=1
else:
ot+=1
print("total vowel characters are",v)
print("total consonant characters are",c)print("total other characters are",ot)

215
Ques98:Write a python program to print the following pattern in string
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
Sol:
str=input("ENTER A STRING")
for i in range(len(str)):
for j in range(len(str),i-1,-1):
print(" ",end="")
for k in range(i+1):
if(k==0 or k==i or j==len(str)-1):
print(str[k],end=" ")
else:
print(" ",end=" ")
print()

216
Ques 99:Write a program in python to reverse a string
Sol:
str=input("Enter any string")
for i in range(len(str)-1,-1,-1):
print(str[i],end=" ")

217
Ques 100:Write a program to print the following pattern
c
co
c m
c p
c u
c t
c e
computer
Sol:
str=input("ENTER A STRING")
for i in range(len(str)):
for j in range(len(str),i-1,-1):
print(" ",end="")
for k in range(i+1):
if(k==0 or k==i or j==len(str)-1):
print(str[k],end=" ")
else:
print(" ",end=" ")
print()

218
Ques 101:Write a program in python to take input in a string and reverse the string
without changing the meaning of the word
Sol:
str=input("ENTER A STRING")
p=str.split()
q=p[::-1]
q=" ".join(q)
print("THE UPDATED STRING IS",q)

219
Ques102:Write a program in python to take input in a string and reverse the string
without changing the string
Sol:
newstr=""
str=input("ENTER A STRING")
p=str.split()
for i in p:
q=i[::-1]
newstr+=q+" "
print("THE UPDATED STRING IS",newstr)

220
Ques 103:Write a program in python to take input in a string and count the number of
character,alphabet,digits,spaces,consonants and special character
Sol:
str=input("Enter a string")
c=a=d=v=s=cn=sc=0
vow="AEIOUaeiou"
for i in range(0,len(str)):
if(str[i]>='A' and str[i]<='Z')or(str[i]>='a' and str[i]<='z'):
a+=1
if str[i] in vow:
v+=1
else:
cn+=1
elif(str[i]>='0' and str[i]<='9'):
d+=1
elif ' ' in str[i]:
s+=1
sc+=1
else:
sc+=1
c+=1
print("Total no. of characters=",c)
print("Total no. of alphabets=",a)
print("Total no. of vowels=",v)
print("Total no. of spaces=",s)
print("Total no. of digits=",d)

221
222
print("Total no. of consonants=",cn)

223
Ques 104:Write a program in python to take input in a string and check if it is
palindrome or not
Sol:
str=input("ENTER A STRING")
flag=False
for i in range(len(str)//2+1):
if str[i]==str[len(str)-i-1]:
flag=True
else:
flag=False
break
if flag==True:
print("%s is a palindrome string"%(str))
else:
print("%s is not a palindrome string"%(str))

224
Ques 105:Write a program to take input as a string and print a string that capitalize
every other letter in the string
Sol:
str=input("ENTER ANY STRING")
for i in range(len(str)):
if i%2==0:
print(str[i].upper(),end="")
else:
print(str[i].lower(),end="")

225
Ques 106:Write a program in python to reads a string and print the string that first
letter should be lower and rest in upper case
Sol:
str=input("ENTER ANY STRING")
print(str.capitalize().swapcase())

226
Ques 107:Write a program to insert element in a list [Method-1]
Sol:
l=[]
n=int(input("HOW MANY NUMBERS YOU WANT TO ENTER INTO LIST"))

for i in range(n):
p=int(input("enter the element%d"%(i+1)))
l.append(p)
print("THE LIST IS")

227
print(l)

228
Ques 108:Write a program to insert element in a list [Method-2]
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)

229
Ques 109:Write a program to take input in a list and shift all the negative elements to
the left of the list
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is :",l)
s=0
for i in range(len(l)):
if l[s]>=0:
q=l.pop(i)
l.append(q)
s-=1
s+=1
print ("the updated list is:",l)

230
Ques 110:Write a program to take input in a list and do linear search
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
search=int(input("ENTER THE NUMBER YOU WANT TO SEARCH"))
for i in range(len(l)):
if l[i]==search:
flag=True
break
else:
flag=False
if flag==True:
print("THE SEARCH ELEMENT %d IS FOUND IN %d POSITION"%(search,i+1))
else:
print("THE SEARCH ELEMENT %d IS NOT FOUND"%(search))

231
Ques 111:Write a program to take input in a list and do binary search
Sol:
l=[]
ch='y'
while ch.upper()=='Y':
p=int(input("Enter any number: "))
l.append(p)
ch=input("Do you want to enter more data(y/n): ")
l.sort()
print("The list is ",l)
search=int(input("Enter the number you want to search: "))
low=0
high=len(l)-1
while low <=high:
mid=(low+high)//2
if l[mid]<search:
low=mid+1
elif l[mid]>search:
high=mid-1
else:
flag=True
pos=mid
break
if low>high:
flag=False
if flag==True:
print("The search element %d is found in %d position "%(search,pos+1))
else:
print(“The search element %d is not found “%(search))

232
233
Ques 112:Write a program to take input in a list and print the second smallest
element in the list
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
small=l[0]
ssmall=l[0]
for i in range(1,len(l)):
if small >l[i]:
ssmall=small
small=l[i]
elif l[i]>small and l[i]<ssmall:
ssmall=l[i]
print("the second smallest number is",ssmall)

234
Ques 113:Write a program to take input in a list and shift the first half of the element
in the list to the other half
Sol:
import math
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
p=math.ceil(len(l)/2)
for i in range(len(l)//2):
l[i],l[p+i]=l[p+i],l[i]
print("the updated list is ",l)

235
Ques 114:Write a program to take input in a list and print the second largest element
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
large=l[0]
slarge=l[0]
for i in range(1,len(l)):
if large<l[i]:
slarge=large
large=l[i]
elif l[i]<large and l[i]>slarge:
slarge=l[i]
print("the second smallest number is",slarge)

236
Ques 115:Write a program to take input in a list and remove the duplicate element
from the list
Sol:
import math
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
for i in range(len(l)):
for i in l:
if l.count(i)>1:
l.remove(i)
print("the updated list is",l)

237
Ques 116:Write a program to take input in the list and do bubble sort
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("The updated list is",l)
for i in range(len(l)-1):
for j in range(len(l)-i-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
print("the sorted list is",l)

238
Ques 117:Write a program to take input in a list and do insertion sort
Sol:
l=[]
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
print("the list is",l)
for i in range (1,len(l)):
value=l[i]
pos=i

while pos>0 and value<l[pos-1]:


l[pos]=l[pos-1]
pos-=1

l[pos]=value
print("THE SORTED LIST IS",l)

239
Ques 118:Write a program to find the sum of two matrices
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
B=[[0 for col in range(n)]for row in range(m)]
C=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("ENTER THE VALUE in 2nd MATRIX")
print("-" *40)
for i in range(m):
for j in range(n):
B[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
for i in range(m):
for j in range(n):
C[i][j]=A[i][j]+B[i][j]
print()
print("THE 1ST MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("THE 2ND MATRIX IS")
print("-" *40)
240
for i in range(m):
for j in range(n):
print("{0:^3}".format(B[i][j]),end=" ")
print()
print()
print("THE ADDITION OF TWO MARTRICES ARE")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(C[i][j]),end=" ")
print()

241
Ques 119:Witie a program to find the difference of two matrices
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
B=[[0 for col in range(n)]for row in range(m)]
C=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("ENTER THE VALUE in 2nd MATRIX")
print("-" *40)
for i in range(m):
for j in range(n):
B[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
for i in range(m):
for j in range(n):
C[i][j]=A[i][j]-B[i][j]
print()
print("THE 1ST MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("THE 2ND MATRIX IS")
print("-" *40)
242
for i in range(m):
for j in range(n):
print("{0:^3}".format(B[i][j]),end=" ")
print()
print()
print("THE SUBSTRACTION OF TWO MARTRICES ARE")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(C[i][j]),end=" ")
print()

243
Ques 120:Write a program to find the multiplication of two matrices
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
p=int(input("Enter the number of rows of the matrix: "))
q=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
B=[[0 for col in range(q)]for row in range(p)]
C=[[0 for col in range(q)]for row in range(m)]
if n==p:
print("Enter the value in 1st matrix")
print("-"*40)
for i in range(m):
for j in range(n):
A[i][j]=int(input("enter the value in[%d] [%d] position"%(i,j)))
print()
print("enter the value in 2nd matrix")
print("_"*40)
for i in range(p):
for j in range(q):
B[i][j]=int(input("enter the value in[%d] [%d] position"%(i,j)))
print()
for i in range(m):
for j in range(q):
C[i][j]=0
for k in range(n):
C[i][j]+=A[i][k]*B[k][j]
print("The 1st mstrix is")
print("-"*40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
244
print()
print()
print("The second matrix is ")
print("-"*40)
for i in range(p):
for j in range(q):
print("{0:^3}".format(B[i][j]),end=" ")
print()
print()
print("The multiplication of two matrices are")
for i in range(m):
for j in range(q):
print("{0:^3}".format(C[i][j]),end=" ")
print()
print()
else:
print("MATRIX MUL NOT POSSIBLE")

245
Ques 121:Write a program to input a matrix and transposed it
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enteyr the value in [%d][%d] position: "%(i,j)))
print()
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("transpose of matrix is")
for i in range(n):
for j in range(m):
print("{0:^3}".format(A[j][i]),end=" ")
print()

246
Ques122:Write a program to print the primary and secondary diagonal
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("primary diagonal:")
print("-" *40)
for i in range(m):
for j in range(n):
if i==j:
print(A[i][j],end=" ")
print()
print("Secondary diagonal:")
print("-" *40)
for i in range(m):
print(A[i][m-i-1],end=" ")
print()
247
248
Ques 123:Write a program to print sum of diagonals
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
c=0
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("primary diagonal:")
print("-" *40)
for i in range(m):
for j in range(n):
if i==j:
c=c+A[i][j]
print(A[i][j],end=" ")
print()
print("Secondary diagonal:")
print("-" *40)
for i in range(m):
c=c+A[i][m-i-1]
249
print(A[i][m-i-1],end=" ")
print()
print("Sum of diagonal :")
print("-" *40)
print(c)

250
Ques 124:Write a program to print upper and lower half of a square matrix
#UPPER HALF OF PRIMARY DIAGONAL
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("Upper half:")
print("-" *40)
for i in range(m):
for j in range(m-i):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()

251
252
#UPPER HALF OF SECONDARY DIAGONAL
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("Lower half:")
print("-" *40)
for i in range(m):
for j in range(m):
if j>=i:
print(A[i][j],end=" ")
else:
print(" ",end=" ")
print()

253
254
print()
#LOWER HALF OF PRIMARY DIAGONAL
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("lower half of secondary diagonal:")
print("-" *40)
for i in range(m):
for j in range(i+1):
print(A[i][j],end=" ")
print()

255
256
print()
#LOWER HALF OF SECONDARY DIAGONAL
Sol:
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print()
print("Enter the value in 1st matrix")
print("-" *40)
for i in range (m):
for j in range(n):
A[i][j]=int(input("Enter the value in [%d][%d] position: "%(i,j)))
print()
print("THE MATRIX IS")
print("-" *40)
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
print("lower half of secondary diagonal:")
print("-" *40)
for i in range(m):
for j in range(m):
if i+j>1:
print(A[i][j],end=" ")
else:
print(" ",end=" ")
print()

257
258
print()
Ques 125:Write a program using function to find the sum of two numbers
Sol:
#127function having argument but not returning value
def addition(m,n):
sum=m+n
print("Sum of %d and %d is %d"%(m,n,sum))
def main():
m=int(input("Enter the first number: "))
n=int(input("Enter the second number: "))
addition(m,n)
main()

259
Ques 126:Write a program using function to find the sum of two numbers
Sol:
#128function having argument but returning value
def addition(m,n):
sum=m+n
return sum
def main():
m=int(input("Enter the first number: "))
n=int(input("Enter the second number: "))
p=addition(m,n)
print("Sum of %d and %d is %d"%(m,n,p))
main()

260
Ques 127:Write a program using function to find the sum of two numbers
Sol:
#129function having no argument but returning value
def addition():
m=int(input("Enter the first number: "))
n=int(input("Enter the second number: "))
sum=m+n
return m,n,sum
def main():
p,q,r=addition()
print("Sum of %d and %d is %d"%(p,q,r))
main()

261
Ques 128:Write a program using function to find the sum of two numbers
Sol:
#130function having no argument but no returning value
def addition():
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
sum=a+b
print("Sum of %d and %d is %d"%(a,b,sum))
def main():
addition()
main()

262
Ques 129:Write a program using function to find the product of two numbers
Sol:
#131function having argument but not returning value
def multiplication (a,b):
mul=a*b
print("Multiplication of %d by %d is %d"%(a,b,mul))
def main():
p=int(input("Enter the first number: "))
q=int(input("Enter the second number: "))
multiplication(p,q)
main()

263
Ques 130:Write a program using function to find the product of two numbers
Sol:
#132function having argument but returning value
def multiplication (p,q):
mul=p*q
return mul
def main():
p=int(input("Enter the first number: "))
q=int(input("Enter the second number: "))
m=multiplication(p,q)
print("Multiplication of %d by %d is %d"%(p,q,m))
main()

264
Ques 131:Write a program using function to find the product of two numbers
Sol:
#133function having no argument but returning value
def multiplication():
m=int(input("Enter the first number: "))
n=int(input("Enter the second number: "))
mul=m*n
return m,n,mul
def main():
p,q,r=multiplication()
print("Multiplication of %d by %d is %d"%(p,q,r))
main()

265
Ques 132:Write a program using function to find the product of two numbers
Sol:
#134function having no argument but no returning value
def multiplication():
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
mul=a*b
print("Multiplication of %d by %d is %d"%(a,b,mul))
def main():
multiplication()
main()

266
Ques 133:Write a program in python to find the division of two numbers
Sol:
def division(a,b):
if b==0:
return False
else:
div=a/b
return div
def main():
a=int(input("Enter the numerator: "))
b=int(input("Enter the denominator: "))
p=division(a,b)
if p==False:
print("Cannot divide by zero")
else:
print("Division of %d by %d is %f"%(a,b,p))
main()

267
Ques 134:Write a program to find greatest of two numbers

Sol:
def greatest(a,b):
if a>b:
return a
else:
return b
def main():
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
print(greatest(a,b),"is the greatest number")

268
main()

269
Ques 135:Write a program to find greatest of three numbers
Sol:
def greatest(a,b,c):
if a>b and b>c:
return a
elif b>c:
return b
else:
return c
def main():
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
c=int(input("Enter the third number: "))
print(greatest(a,b,c),"is the greatest number")

270
main()

Ques 136:Write a program to find a number is even or odd


Sol:
def number(a):
if a%2==0:
return True
else:
return False
def main():
a=int(input("Enter the number: "))
p=number(a)
if p==False:
print("%d is an odd number"%(a))
else:
print("%d is an even number"%(a))

271
main()

272
Ques 137:Write a program to find area of a circle
Sol:
import math
defareacir(r):
return(math.pi*math.pow(r,2))
def main():
r=int(input("Enter the radius of circle: "))
p=areacir(r)
print("Area of circle is",p)
main()

273
Ques 138:Write a program to find roots of a quadratic equation
Sol:
import math
def quadratic(a,b,c):
if a==0:
print("This is not a Quadratic Equation")
else:
d=b*b-4*a*c
if d<0:
print("Roots are imaginary")
elif d==0:
x=-b/(2*a)
print("Roots of the equation is",x)
else:
x1=(-b+math.sqrt(d)/(2*a))
x2=(-b-math.sqrt(d)/(2*a))
print("Roots of the equation are",x1,x2)
def main():
a=int(input("Enter the value of a: "))
b=int(input("Enter the value of b: "))
c=int(input("Enter the value of c: "))
quadratic(a,b,c)
main()

274
Ques 139:Write a program to check a number is positive or negative
Sol:
def number(n):
if n>=0:
return True
else:
return False
def main():
n=int(input("Enter the number: "))
p=number(n)
if p==True:
print("%d is a Positive Number"%(n))
else:
print("%d is a Negative Number"%(n))
main()

275
Ques 140:Write a program to find the simple interest
Sol:
defsimple_interest(p,r,t):
si=(p*r*t)/100
return si
def main():
p=int(input("Enter the Principle Amount: "))
r=int(input("Enter the Rate of Interest: "))
t=int(input("Enter the Time: "))
print("The Simple Interest is",simple_interest(p,r,t))
main()

276
Ques 141:Write a program to find smallest of three numbers
Sol:
def smallest(a,b,c):
if a<b and a<c:
return a
elif b<c:
return b
else:
return c
def main():
a=int(input("Enter the First Number: "))
b=int(input("Enter the Second Number: "))
c=int(input("Enter the Third Number: "))
print(smallest(a,b,c),"is the Smallest Number")
main()

277
Ques 142:Write a menu driven program to do addition,subtraction,multiplication,
Division
Sol:
def addition(a,b):
sum=a+b
return sum
def sub(a,b):
subt=a-b
return subt
defmul(a,b):
mul=a*b
return mul
def division(a,b):
if b==0:
return False
else:
return(a/b)
def main():
print('''Menu
1.Addition
2.Subtraction
3.Multiplication
4.Division''')
ch=int(input("Enter your choice"))
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
if ch==1:
print("Addition of %d and %d is %d"%(a,b,addition(a,b)))
elifch==2:
print("Subtraction of %d and %d is %d"%(a,b,sub(a,b)))
elifch==3:
print("Multiplication of %d and %d is %d"%(a,b,mul(a,b)))
278
elifch==4:
p=division(a,b)
if p==False:
print("Cannot divide by zero")
else:
print("Division of %d by %d is %f"%(a,b,p))
else:
print("Wrong choice")
main()

279
Ques 143:Write a menu driven program to find compound interest and simple interest
Sol:
def si(p,r,t):
return((p*r*t)/100)
def ci(p,r,t):
com=p*(1+r/100)**t
return com
def main():
while True:
while True:
print('''Menu
1.calculate Simple Interest
2.calculate Compound Interest''')
ch=int(input("Enter your choice:"))
if ch>2:
print("Wrong Choice")
break
p=int(input("Enter the principal amount:"))
r=int(input("Enter the rate of interest:"))
t=int(input("Enter the time period:"))
if ch==1:
print("Simple interest is",si(p,r,t))
elif ch==2:
print("Compound interest is",ci(p,r,t))
ch1=input("Do you want to continue:(y/n)")
if ch1.upper()=='Y':
continue
else:
break
main()

280
281
Ques 144:Write a menu driven program to find area of square, rectangle,
triangle,circle,rhombus,paralleogram and trapizum and the volume of
cube,cuboid,cylinder,sphere,hemisphere and cone (Using function)
Sol:
import math
def square(l):
return(l*l)
def rectangle(l,b):
return(l*b)
def circle(r):
return(math.pi*math.pow(r,2))
def triangle(a,b,c):
s=(a+b+c)/2
return(math.sqrt(s*(s-a)*(s-b)*(s-c)))
def parallel(b,h):
return(b*h)
def trap(a,b,h):
return(((a+b)*h)/2)
def cube(s):
return(s*s*s)
def cuboid(l,b,h):
return(l*b*h)
def cylinder(r,h):
return(math.pi*math.pow(r,2)*h)
def sphere(r):
return(4*(math.pi*r*r*r)/3)
def hemisphere(r):
return(2*(math.pi*r*r*r)/3)
def cone(r,h):
return((math.pi*r*r*h)/3)
def main():

282
while True:
print('''1.Area
2.Volume''')
ch=int(input("Enter your choice:"))
if ch==1:
print('''1.Area of Square
2.Area of Rectangle
3.Area of Circle
4.Area of Triangle
5.Area of Parallelogram
6.Area of Trapezium''')
c=int(input("Enter your choice:"))
if c==1:
l=int(input("Enter the side of square:"))
print("Area of Square is",square(l))
elif c==2:
l=int(input("Enter the length of rectangle:"))
b=int(input("Enter the breadth of rectangle:"))
print("Area of Rectangle is",rectangle(l,b))
elif c==3:
r=int(input("Enter the radius of circle:"))
print("Area of Circle is",circle(r))
elif c==4:
a=int(input("Enter the first side of triangle:"))
b=int(input("Enter the second side of triangle:"))
c=int(input("Enter the third side of triangle:"))
print("Area of Triangle is",triangle(a,b,c))
elif c==5:
b=int(input("Enter the base of the parallelogram:"))
h=int(input("Enter the height of the parallelogram:"))
print("Area of Parallelogram is",parallel(b,h))
elif c==6:
283
a=int(input("Enter the first parallel side:"))
b=int(input("Enter the second parallel side:"))
h=int(input("Enter the height of the trapezium:"))
print("Area of Trapezium is",trap(a,b,h))
else:
print("Wrong choice")
elif ch==2:
print('''1.Volume of Cube
2.Volume of Cuboid
3.Volume of Cylinder
4.Volume of Sphere
5.Volume of Hemisphere
6.Volume of Cone''')
c=int(input("Enter your choice:"))
if c==1:
s=int(input("Enter the side of cube:"))
print("Volume of Cube is",cube(s))
elif c==2:
l=int(input("Enter the length of cuboid:"))
b=int(input("Enter the breadth of cuboid:"))
h=int(input("Enter the height of cuboid:"))
print("Volume of Cuboid is",cuboid(l,b,h))
elif c==3:
r=int(input("Enter the radius of cylinder:"))
h=int(input("Enter the height of cylinder:"))
print("Volume of Cylinder is",cylinder(r,h))
elif c==4:
r=int(input("Enter the radius of sphere:"))
print("Volume of Sphere is",sphere(r))
elif c==5:
r=int(input("Enter the radius of hemisphere:"))
print("Volume of Hemisphere is",hemisphere(r))
284
elif c==6:
r=int(input("Enter the radius of cone:"))
h=int(input("Enter the height of cone:"))
print("Volume of Cone is",cone(r,h))
else:
print("Wrong choice")
else:
print("Wrong choice")
c=input("Do you want to continue(y/n)")
if c=='Y' or c=='y':
continue
else:
break
main()

285
Ques 145:Write a program to swap two numbers without using third variable
Sol:
def swap(m,n):
m=m+n
n=m-n
m=m-n
return (m,n)
def main():
m=int(input("Enter the First Number: "))
n=int(input("Enter the Second Number: "))
print("Before Swapping")
print("M =",m)
print("N =",n)
m=m+n
n=m-n
m=m-n
print("After Swapping")
print("M =",m)
print("N =",n)
main()

286
Ques 146:Write a program to find prime between certain range
Sol:
def prime(n):
c=0
for i in range (1,n//2+1):
if n%i==0:
c+=1
if c==1:
return True
else:
return False
def main():
p=int(input ("Enter the number"))
a=prime(p)
if a==True:
print("%d is a prime number"%(p))
else:
print("%d is not a prime number"%(p))
main()
Ques 147:Write a program to find the sum of natural numbers

287
Sol:
def natural (n):
s=0
for i in range(1,n+1):
s+=i
return s
def main():
n=int(input("Enter the value of n :"))
s=natural(n)
print("Sum of ",n,"natural number :",s)
main()

288
Ques 148:Write a program to find the factorial of a number
Sol:
def fact(n):
s=1
for i in range(1,n+1):
s=s*i
return s
def main():
n=int(input("Enter the number"))
p=fact(n)
print("factorial of %d is %d"%(n,p))
main()

289
Ques 149:Write a program to find the fibonacci series
Sol:
deffibo(a,b):
s=a+b
return s
def main():
n=int(input("Enter the no of terms:"))
a=0
b=1
print(a,b,end=" ")
for i in range (3,n+1):
p=fibo(a,b)
a=b
b=p
print(p,end=" ")
main()

290
Ques 150:Write a program to print the following pattern
*
**
***
****
*****
Sol:
def pattern(n):
for i in range(n):
for j in range(i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pattern(n)
main()

291
Ques 151:Write a program to print the following pattern
*
**
***
****
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print(" ",end="")
for k in range(1,i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the no of rows:"))
pat(n)
main()

292
Ques 152:Write a program to print the following pattern
*****
****
***
**
*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,i+1):
print(" ",end="")
for k in range(n-i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the no of rows:"))
pat(n)
main()

293
Ques 153:Write a program to print the following pattern
*
**
***
****
***
**
*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
print("*",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the no of rows:"))
pat(n)
main()

294
Ques 154:Write a program to print the following pattern
*
**
***
**
*
**
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
print("*",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
print("*",end=" ")
print()
for i in range(n-2,0,-1):
for j in range(1,i+2):
print("",end=" ")
for k in range(1,n-i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the no of rows:"))
pat(n)

295
296
main()
Ques 155:Write a program to print the following pattern
*
**
* *
* *
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i or i==n:
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()
Ques 156:Write a program to print the following pattern

297
*
**
* *
* *
* *
* *
* *
**
*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
298
main()

299
Ques 157:Write a program to print the following pattern
*
**
* *
**
*
**
* *
**
*
Sol:
def pat(n):
for i in range(1,n+1):

for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(2,n+1):
300
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i:
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

301
Ques 158:Write a program to print the following pattern
*
**
*#*
*##*
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print("",end=" ")
for k in range(1,i+1):
if k==1 or k==i or i==n:
print("*",end=" ")
else:
print("#",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

302
Ques 159:Write a program to print the following pattern
*
**
*#*
*##*
*#@#*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print(" ",end="")
for k in range(1,i+1):
if(k==1 or k==i):
print("*",end=" ")
elif(k==2 or k==i-1):
print("#",end=" ")
else:
print("@",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

303
Ques 160:Write a program to print the following pattern
*
***
*****
*******
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print(" ",end=" ")
for k in range(1,i*2):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

304
Ques 161:Write a program to print the following pattern
*
* *
* *
* *
*****
* *
* *
* *
*
Sol:
def pat(n):
for i in range (1,n+1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range (1,i*2):
if k==1 or k==i*2-1:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range (n-1,0,-1):
for j in range(1,n-i+1):
if i==1:
break
print(" ",end=" ")
for k in range (1,i*2):
if(i!=1):
if k==1 or k==i*2-1:
print("*",end=" ")
else:
print(" ",end=" ")
305
else:
for m in range(1,n*2):
print("*",end=" ")
print()
for i in range (2,n+1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range (1,i*2):
if k==1 or k==i*2-1:
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range (n-1,0,-1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range (1,i*2):
if k==1 or k==i*2-1:
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

306
Ques 162:Write a program to print the following pattern
1
12
123
1234
12345
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

307
308
Ques 163:Write a program to print the following pattern
*****
* *
* *
* *
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n+1):
if(j==1 or j==n) or (i==1 or i==n):
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

309
Ques 164:Write a program to print the following pattern
*****
* ** *
** **
** **
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n+1):
if i==1 or i==n:
print("*",end=" ")
elif j==1:
print("*",end="")
else:
print("",end="")
if i==1 or i==n:
print("",end="")
else:
for k in range(2,n-i+1):
print("",end=" ")
for l in range(1,i+1):
if l==n-1:
print("*",end="")
elif l==1 or l==i:
print("*",end=" ")
else:
print(" ",end=" ")
for m in range(2,n-i):
print("",end=" ")
print("*",end="")
print()
310
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

311
312
Ques 165:Write a program to print the following pattern
*********
* * * *
* * * *
** **
* *
** **
* * * *
* * * *
*********
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
if(j==1 or j==n-i+1 or i==1):
print("*",end=" ")
else:
print(" ",end=" ")
for m in range(2,i*2-1):
print(" ",end=" ")
for k in range(n-i+2,1,-1):
if(k==n-i+2 or k==2 or i==1):
if(k<=n):
print("*",end=" ")
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i+2):
if(j==1 or j==n-i+1 or i==1):
print("*",end=" ")
else:
313
print(" ",end=" ")
for m in range(2,i*2-1):
print(" ",end=" ")
for k in range(1,n-i+2):
if(k==n-i+1 or k==1 or i==1):
if(k<n):
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main

314
Ques 166:Write a program to print the following pattern
*****
***
*
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(n*2,i*2-1,-1):
print("",end=" ")
for k in range(1,i*2):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

315
Ques 167:Write a program to print the following pattern
Sol:
* *
** **
*** ***
**** ****
***** *****
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(0,n-i+1):
print("*",end=" ")
for k in range(1,i*2):
print(" ",end=" ")
for m in range(0,n-i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

316
Ques 168:Write a program to print the following pattern
Sol:
* *
** **
*** ***
********
*** ***
** **
* *
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(1,n-i+2):
print("*",end=" ")
for k in range(1,i*2-1):
print(" ",end=" ")
for m in range(1,n-i+2):
print("*",end=" ")
print()
for i in range(2,n+1):
for j in range(1,n-i+2):
print("*",end=" ")
for k in range(1,i*2-1):
print(" ",end=" ")
for m in range(1,n-i+2):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

317
318
main()
Ques 169:Write a program to print the following pattern
*
**
***
****
*****
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(n,i,-1):
print(" ",end=" ")
for k in range(1,i+1):
print("*",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

319
Ques 170:Write a program to print the following pattern
*
*
*****
*
*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n+1):
if(j==(n+1)//2) or (i==(n+1)//2):
print("*",end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

320
Ques 171:Write a program to print the following pattern
1
21
321
4321
54321
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(i,0,-1):
print(j,end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

321
Ques 172:Write a program to print the following pattern
54321
4321
321
21
1
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(i,0,-1):
print(j,end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

322
Ques 173:Write a program to print the following pattern
1
23
456
7 8 9 10
Sol:
def pat(n):
m=1
for i in range(1,n+1):
for k in range(1,n-i+2):
print(" ",end="")
for j in range(1,i+1):
print(m,end=" ")
m+=1
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

323
Ques 174:Write a program to print the following pattern
1
32
654
10 9 8 7
15 14 13 12 11
Sol:
def pat(n):
p=1
for i in range(1,n+1):
p+=i
for j in range(1,n-i+2):
print(" ",end="")
for k in range(1,i+1):
print((p-k),end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

324
Ques 175:Write a program to print the following pattern
Sol:
*
*@*
*@#@*
*@#@#@*
*********
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range(1,i*2):
if(k==1 or k==i*2-1)or i==n:
print("*",end=" ")
elif(k==2 or k==i*2-2):
print("@",end=" ")
elif(k==3 or k==i*2-3):
print("#",end=" ")
else:
print("@",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

325
Ques 176:Write a program to print the following pattern
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+2):
print(" ",end=" ")
p=1
for k in range(1,i+1):
print(" ",p,sep=" ",end=" ")
p=p*(i-k)//k
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

326
Ques 177:Write a program to print the following pattern
1
121
12321
1234321
123454321
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(2*n,2*i-1,-1):
print(" ",end="")
for k in range(1,i+1):
print(k,end=" ")
for l in range(i-1,0,-1):
print(l,end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

327
Ques 178:Write a program to print the following pattern
1
212
32123
4321234
543212345
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range(i,0,-1):
print(k,end=" ")
for l in range(2,i+1):
print(l,end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

328
Ques 179:Write a program to print the pattern
*@@@*
*@*
*
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(1,n-i+2):
print(" ",end=" ")
for k in range(1,i*2):
if (k==1 or k==i*2-1):
print("*",end=" ")
else:
print("@",end=" ")
print()
def main():
n=int(input("Enter the number of rows"))
pat(n)
main()

329
Ques 180:Write a program to print the pattern
1
212
32123
4321234
*@@@@@*
*@@@*
*@*
*
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range(i,0,-1):
print(k,end=" ")
for l in range(2,i+1):
print(l,end=" ")
print()
for i in range(n,0,-1):
for j in range(1,n-i+1):
print(" ",end=" ")
for k in range(1,i*2):
if (k==1 or k==i*2-1):
print("*",end=" ")
else:
print("@",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)

330
331
main()
Quse 181:Write a program to print the pattern

1234
2 3
3 2
4321
Sol:
def pat(n):
for i in range(1,n+1):
for j in range(1,n+1):
if(i==1):
print(j,end=" ")
elif(i==n):
print(n-j+1,end=" ")
elif(j==1):
print(i,end=" ")
elif(j==n):
print(n-i+1,end=" ")
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

332
Quse 182:Write a program to print the pattern
456
23
1
23
456
Sol:
def pat(n):
for i in range(n,0,-1):
for j in range(1,n-i+2):
print(" ",end="")
for k in range(i*(i+1)//2-i,i*(i+1)//2):
print(k+1,end=" ")
print()
for i in range(2,n+1):
for j in range(1,n-i+2):
print(" ",end="")
for k in range(i*(i+1)//2-i,i*(i+1)//2):
print(k+1,end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

333
Ques 183:Write a program to print the pattern
1
2 3
4 5
6 7 8 9
Sol:
def pat(n):
p=1
for i in range(1,n):
for j in range(1,n-i+2):
print(" ",end=" ")
for k in range(1,i*2):
if (k==1 or k==i*2-1) or (i==1):
print(p,end=" ")
p=p+1
else:
print(" ",end=" ")
print()
for i in range(1,n*2+1):
if (i%2==0):
print(p,end=" ")
p=p+1
else:
print(" ",end=" ")
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)

334
335
main()
Ques 184:Write a program to print the pattern
1
23
4 5
6789
10 11
12 13
14
Sol:
def pat(n):
m=1
for i in range(1,n+1):
for j in range(1,n-i+1):
print("",end=" ")
for k in range(1,i+1):
if(k==1 or k==i or i==n):
print(m,end=" ")
m+=1
else:
print(" ",end=" ")
print()
for i in range(n-1,0,-1):
for j in range(1,n-i):
print("",end=" ")
for k in range(1,i+1):
if(k==1 or k==i):
print(m,end=" ")
m+=1
else:
print(" ",end=" ")
print()
336
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

337
Quse185:Write a program to print the pattern
A
AB
ABC
ABCD
ABCDE
Sol:
def pattern(n):
for i in range(1,n+1):
ch=65
for j in range(1,n-i+2):
print("",end=" ")
for k in range(1,i+1):
print(chr(ch),end=" ")
ch+=1
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

338
Ques186:Write a program to print the pattern(Using function)
A
ABC
ABCDE
Sol:
def pattern(n):
for i in range(1,n+1):
Ch=65
for j in range(1,n-i+2):
print(" ",end="")
for k in range(1,i*2):
print(chr(Ch),end=" ")
Ch+=1
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

339
Quse187:Write a program to print the pattern(Using function)
A
BA
CBA
DCBA
Sol:
def pattern(n):
for i in range(1,n+1):
Ch=65+i-1
for j in range(1,n-i+2):
print(" ",end="")
for k in range(1,i+1):
print(chr(Ch),end=" ")
Ch-=1
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

340
Ques188:Write a program to print the pattern(Using function)
A
CB
FED
JIHG
Sol:
def pattern(n):
for i in range(1,n+1):
Ch=65+(i*(i+1)//2)-1
for j in range(1,n-i+1):
print(" ",end="")
for k in range(1,i+1):
print(chr(Ch),end=" ")
Ch-=1
341
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

Ques 189:Write a program to print the pattern using function


ONMLK
JIHG
FED
CB
A
Sol:
def pattern(n):
Ch=65+(n*(n+1)//2)-1
for i in range(n,0,-1):
for j in range(1,n-i+1):
print("",end=" ")

342
for k in range(1,i+1):
print(chr(Ch),end=" ")
Ch-=1
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

Ques 190:Write a program to print the pattern using function


ABCBA
ABA
A
Sol:
def pattern(n):
for i in range(1,n+1):
Ch=65
for j in range(i*2-1):
print("",end=" ")
343
for k in range(1,(n-i+1)*2):
if k<=n-i+1:
print(chr(Ch),end=" ")
else:
Ch-=2
print(chr(Ch),end=" ")
Ch+=1
print()
def main():
n=int(input("Enter the number of rows "))
pattern(n)
main()

344
Ques 191:Write a program to print the pattern using function
CBABC
BAB
A
Sol:
def pattern(n):
for i in range(1,n+1):
Ch=65+n-i
for j in range(1,i*2):
print("",end=" ")
for k in range(1,(n-i+1)*2):
if k<=n-i+1:
print(chr(Ch),end=" ")
Ch=Ch-1
else:
Ch=Ch+1
print(chr(Ch+1),end=" ")
print()
def main():
n=int(input("Enter the number of rows "))

pattern(n)
main()

345
Ques 192:Write a program to print the pattern using function
A
B1B
C121C
DCBABCD
Sol:
def pattern(n):
ch=65
for i in range(1,n+1):
c=1
for j in range(1,(n*2)-(i*2)+1):
print("",end=" ")
for k in range(1,i*2):
if i==n:
if k<=n:
print(chr(ch),end=" ")
ch-=1
else:
ch+=1
print(chr(ch+1),end=" ")
elif k==1 or k==i*2-1:
print(chr(ch),end=" ")
elif k<=i:
print(c,end=" ")
c+=1
else:
c-=1
print((c-1),end=" ")
ch+=1
print()
def main():
n=int(input("enter the number of rows"))
346
pattern(n)
main()

347
Ques 193:Write a program to print the pattern using function
1
CBA
54321
Sol:
def pat(n):
for i in range(1,n+1):
ch=65+(2*(i-1))
for j in range(1,n*2-i*2+1):
print("",end=" ")
for k in range(i*2-1,0,-1):
if (i%2!=0):
print(k,end=" ")
else:
print(chr(ch),end=" ")
ch-=1
print()
def main():
n=int(input("Enter the number of rows:"))
pat(n)
main()

348
Ques 194:Write a program to print the sum of series using function
1+2+3+4…+n
Sol:
def series(n):
sum=0
for i in range(1,n+1):
sum+=i
return sum
def main():
n=int(input("enter the no. terms"))
p=series(n)
print("sum of series is %d"%(p))
main()

349
Ques 195:Write a program to print the sum of series using function
1-2+3-4….n
Sol: def series(n):
sum=0
for i in range(1,n+1):
sum+=(-1)**(i+1)*i
return sum
def main():
n=int(input("enter the no. terms"))
p=series(n)
print("sum of series is %d"%(p))
main()

350
Ques 196:Write a program to print the sum of series using function
-1+1/2-1/3…1/N
Sol:
def series(n):
sum=0
for i in range(1,n+1):
sum +=(-1)**i*(1/i)
return sum
def main():
n=int(input("enter the no. of terms:"))
p=series(n)
print("sum of series is %d ",(p))
main()

351
352
Ques 197:Write a program to print the sum of series using function
1+(1+2)+(1+2+3)+…N
Sol:
def series(n):
sum=0
for i in range(1,n+1):
for j in range(1,i+1):
sum+=j
return sum
def main():
n=int(input("enter the no. of terms:"))
p=series(n)
print("sum of series is %d "%(p))
main()

353
Ques 198:Write a program to print the sum of series using function
X+X²+X³…xN
Sol:
def series(n,x):
sum=0
for i in range(1,n+1):
sum += x**i
return sum
def main():
n=int(input("enter the no. of terms"))
x=int(input( "enter the value of x"))
p=series(n,x)
print("sum of series is%d"%(p))
main()

354
Ques199:Write a program to print the sum of series using function
-1+x/2-x²/3…N
Sol:
def series(x,n):
sum=0
for i in range(1,n+1):
sum +=(-1)**(i)*(x**(i-1))/i
return sum
def main():
x=int(input("Enter the value of x:"))
n=int(input("enter the no. of terms:"))
p=series(x,n)
print("sum of series is %d "%(p))
main()

355
Ques 200:Write a program to print the sum of series using function
1-x/2!+x²/3!....N
Sol:
def facto(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact
def series(x,n):
sum=0
for i in range(1,n+1):
sum+=(-i)**(i+1)*(x**(i-1))/facto(i)
return sum
def main():
x=int(input("Enter the value of x:"))
n=int(input("enter the no. of terms:"))
p=series(x,n)
print("sum of series is %d "%(p))
main()

356
Ques 201:Write a program to print the sum of series using function
1-x²/3!+x⁴/6!...N
Sol:

def facto(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact
def series(x,n):
sum=0
for i in range(1,n+1):
sum+=(-i)**(i+1)*(x**2*(i-1))/facto(3*(i-1))
return sum
def main():
x=int(input("Enter the value of x:"))
n=int(input("enter the no. of terms:"))
p=series(x,n)
print("sum of series is %d "%(p))
main()

357
Ques202:Write a program to print the sum of series using function
1-x5/7!+x10/14!..N
Sol:
def facto(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact
def series(x,n):
sum=0
for i in range(1,n+1):
sum+=(-i)**(i+1)*(x**5*(i-1))/facto(7*(i-1))
return sum
def main():
x=int(input("Enter the value of x:"))
n=int(input("enter the no. of terms:"))
p=series(x,n)
print("sum of series is %d "%(p))
main()

358
Ques 203:Write a program to print the sum of series using function
-6x³/5!+24x5/7!...N
Sol:
def facto(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact
def series(x,n):
sum=0
for i in range(2,n+1):
sum+=(-i)**(i+1)*((i**3)-i)*(x**(2*i+1))/facto(2*i+2)
return sum
def main():
x=int(input("Enter the value of x:"))
n=int(input("enter the no. of terms:"))
p=series(x,n)
print("sum of series is %d "%(p))
main()

359
204:Write a program to check whether a number is palindrome or not using function
Sol:
def pat(n):
p=n
sum=0
while(p!=0):
r=p%10
sum=(sum*10)+r
p=p//10
if sum==n:
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=pat(n)
if p==1:
print("%d is a palindrome number"%(p))
else:
print("%d is not a palindrome number"%(p))
main()

360
Ques205:Write a program to check whether a number is Armstrong or not using
function
Sol:
def pat(n):
p=n
sum=0
while(p!=0):
r=p%10
sum=sum+(r*r*r)
p=p//10
if sum==n:
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=pat(n)
if p==1:
print("%d is a Armstrong number"%(p))
else:
print("%d is not a Armstrong number"%(p))
main()

361
Ques206:Write a program to check whether a number is special or not using function
Sol:
def facto(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact
def series(n):
sum=0
p=n
while(p!=0):
r=p%10
sum+=facto(r)
p//=10
if sum==n:
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=series(n)
if p==1:
print("%d is a Special number"%(p))
else:
print("%d is not a Special number"%(p))

362
363
main()
Ques207:Write a program to check whether a number is perfect or not using function
Sol:
def pat(n):
sum=0
for i in range(1,n):
if n%i==0:
sum+=i
if sum==n:
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=pat(n)
if p==1:
print("%d is a perfect number"%(p))
else:
print("%d is not a perfect number"%(p))
main()

364
Ques208:Write a program to check whether a number is magic number(1) or not
using function
Sol:
def pat(n):
summ=0
sum=0
p=n
while(p!=0):
r=p%10
sum+=r
p//=10
k=sum
while k!=0:
a=k%10
summ=(summ*10)+a
k//=10
if ((sum*summ)==n):
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=pat(n)
if p==1:
print("%d is a magic number"%(p))
else:
print("%d is not a magic number"%(p))

365
366
main()

367
Ques 209:Write a program to check whether a number is magic number(2) or not
using function
Sol:
def magic(n):
s=0
p=n
while p>0:
s+=p%10
p//=10
return s
def main():
c=0
m=int(input("Enter the initial range:"))
n=int(input("Enter the final range:"))
for i in range(m,n+1):
s=magic(i)
while s>9:
s=magic(s)
if s==1:
print(i)
c+=1
print("Total magic number between %d and %d is %d"%(m,n,c))
main()

368
Ques 210:Write a program to print palindrome number between certain range
Sol:
def palin(n):
p=n
s=0
while p!=0:
r=p%10
s=s*10+r
p//=10
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p=palin(i)
if p==i:
print(i)
c+=1
print("Total palindrome numbers between %d and %d is %d"%(m,n,c))
main()

369
Ques 211:Write a program to print Armstrong number between certain range
Sol:
def armst(n):
p=n
s=0
while p!=0:
r=p%10
s+=r**3
p//=10
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p=armst(i)
if p==i:
print(i)
c+=1
print("Total armstrong numbers between %d and %d is %d"%(m,n,c))

370
371
main()
Ques 212:Write a program to print special number between certain range
Sol:
def fact(n):
f=1
for i in range(1,n+1):
f*=i
return f
def special(n):
p=n
s=0
while p!=0:
r=p%10
s+=fact(r)
p//=10
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p=special(i)
if p==i:
print(i)
c+=1
print("Total special numbers between %d and %d is %d"%(m,n,c))

372
373
main()

374
Ques 213:Write a program to print perfect number between certain range
Sol:
def perfect(n):
s=0
for i in range(1,n//2+1):
if n%i==0:
s+=i
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p=perfect(i)
if p==i:
print(i)
c+=1
print("Total perfect numbers between %d and %d is %d"%(m,n,c))

375
376
main()

377
Ques 214:Write a program to print magic naumber1 number between certain range
Sol:
def magic1(n):
p=n
s=0
while p!=0:
r=p%10
s+=r
p//=10
b=0
a=s
while a!=0:
r=a%10
b=b*10+r
a//=10
return b,s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p,q=magic1(i)
if p*q==i:
print(i)
c+=1
print("Total magic numbers between %d and %d is %d"%(m,n,c))

378
379
main()
Ques 215:Write a program to print magic number2 between certain range
Sol:
def magic2(n):
s=0
p=n
while p>0:
s+=p%10
p//=10
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
s=magic2(i)
while s>9:
s=magic2(s)
if s==1:
print(i)
c+=1
print("Total magic numbers between %d and %d is %d"%(m,n,c))

380
381
main()
Ques 216:Write a program to print neon number between certain range
Sol:
def neon(n):
p=n**2
s=0
while p!=0:
s+=p%10
p//=10
return s
def main():
c=0
m=int(input("Enter the first value: "))
n=int(input("Enter the last value: "))
for i in range(m,n+1):
p=neon(i)
if p==i:
print(i)
c+=1
print("Total neon numbers between %d and %d is %d"%(m,n,c))

382
383
main()
Ques217:Write a program to check a number is a neon number or not
Sol:
def pat(n):
sum=0
p=n*n
while p!=0:
r=p%10
sum+=r
p//=10
if sum==n:
return 1
else:
return 0
def main():
n=int(input("enter the number"))
p=pat(n)
if p==1:
print("%d is a neon number"%(p))
else :
print("%d is not a neon number"%(p))
main()

384
Ques 218:Write a program to count the number of vowels,consonants and other character
Sol:
def alfa (str):
vowel="aeiouAEIOU" consta="bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
v=c=ot=0
for i in range(len(str)):
if str[i] in vowel:
v+=1
elif str[i] in consta:
c+=1
else:
ot+=1
return v,c,ot
def main():
str=input("ENTER A STRING")
p,q,r=alfa(str)
print("total vowel characters are",p)
print("total consonant characters are",q)
print("total other characters are",r)
main()

385
Ques 219:Write a program to print the pattern using function
C
Ca
Cat
Sol:
def string(Str):
for i in range(len(Str)):
for j in range(len(Str),i,-1):
print(" ",end="")
for k in range(i+1):
print(Str[k],end=" ")
print( )
def main( ):
Str=input("Enter any string")
string(Str)
main( )
def string(Str):
for i in range(len(Str)):
for j in range(len(Str),i,-1):
print(" ",end="")
for k in range(i+1):
print(Str[k],end=" ")
print( )
def main( ):
Str=input("Enter any string")
string(Str)

386
387
main( )
Ques 220:write a program to reverse a string without changing the meaning
Sol:
def string(Str):
revStr=" "
for i in range(len(Str)-1,-1,-1):
revStr+=Str[i]
return(revStr)
def main( ):
Str=input("Enter any string")
print("The reverse string is",string(Str))
main( )

388
Ques 221:Write a program to print the pattern using function
C
Co
C m
C p
C u
C t
C e
Computer
Sol:
def string(Str):
for i in range(len(Str)):
for j in range(len(Str)-1,i-1,-1):
print(" ",end="")
for k in range(i+1):
if k==0 or k==i or i==len(Str)-1:
print(Str[k],end=" ")
else:
print(" ",end=" ")
print( )
def main( ):
Str=input("Enter any string")
string(Str)
main( )

389
Ques 222:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A STRING AND REVERSE
THAT STRING WITHOUT CHANGING THE MEANING OF WORD
Sol:
def string(Str):
p=Str.split( )
p=p[ : :-1]
p=" ".join(p)
return (p)
def main( ):
Str=input("Enter any string")
print("The reverse string is",string(Str))
main()

390
Ques 223:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A STRING AND RESERVE THAT
WORK AT ITS OWN PLACE

def string(Str):
p=Str[ : :-1]
p=p.split( )
p=p[ : :-1]
p=" ".join(p)
return p
def main( ):
Str=input("Enter any string")
print("The reverse string is",string(Str))
main( )

391
Ques 224:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A STRING AND CHEAK
WHEATHER A STRING IS PALINDROME STRING OR NOT
Sol:
def palin(Str):
flag=False
for i in range(len(Str)//2+1):
if Str[i]==Str[len(Str)-i-1]:
flag=True
else:
flag=False
break
return flag
def main( ):
Str=input("Enter any string")
f=palin(Str)
if f==True:
print("%s is a palindrome string"%(Str))
else:
print("%s is not a palindrome string"%(Str))
main()

392
Ques 225:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A STRING AND COUNTS THE
NUMBER OF VOWELS, CONSONANT AND OTHERS
Sol:
def vowelcount(Str):
vowel="AEIOU"
count=0
for i in Str:
if i.upper( )in vowel:
count+=1
return count
def consocount(Str):
conso="BCDFGHJKLMNPQRSTVWXYZ"
count=0
for i in Str:
if i.upper( )in conso:
count+=1
return count
def main( ):
Str=input("Enter any string")
p=vowelcount(Str)
q=consocount(Str)
print("Total vowel characters are",p)
print("Toral consonant characters are",q)
print("Total other characters are",len(Str)-(p+q))
main()

393
394
main( )
Ques226: WRITE A PROGRAM IN PYTHON USING FUNCTION THAT READS A STRING
AND THEN PRINTS A STRING THAT’S CAPITALIZE EVERY OTHER LETTERS IN THE
STRING
Sol:
def string(str):
result = ' '
for i in range(len(str)):
if i % 2 == 0:
print(str[i].upper( ),end=" ")
else:
print(str[i].lower( ),end=" ")
return result
def main():
str=input("enter any string")
print(" is the reverse string ",string(str))
main()

395
Ques 227: WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT A STRING
AND CONVERT THE STRING TO THE FOLLOWING PATTERN
Sol:
def string(Str):
p=Str.capitalize( )
p=p.swapcase( )
return (p)
def main( ):
Str=input("Enter any string")
print("The reverse string is",string(Str))
main( )

396
Ques 228: Write a program to take input in a list method 1
Sol:
l=[]
def list(n):
for i in range(n):
p=int(input("enter the element%d"%(i+1)))
l.append(p)
print("THE LIST IS")
print(l)
def main():
n=int(input("HOW MANY NUMBERS YOU WANT TO ENTER INTO LIST"))
list(n)
main()

397
Ques 229:Write a program to take input in a list method 2
Sol:
l=[]
def list():
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break
return l
def main():
k=list()
print("The list is",k)
main()

398
Ques 230: WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A LIST AND SHIFT ALL THE
NEGATIVE ELEMENT TO LEFT AND POSITIVE ELEMENT TO RIGHT IN A LIST
Sol:
import math
l=[ ]
def listk():
s=0
for i in range(len(l)):
if l[s]>0:
p=l.pop(s)
l.append(p)
s-=1
s+=1
def inputlist( ):
while True:
n=int(input("Enter any number"))
l.append(n)
ch=input("Do you want to enter more data(y/n)")
if ch.upper()=='Y':
continue
else:
break
def main():
print("Enter the value in list")
inputlist( )
print("The list is",l)
listk()
print("The updated list is",l)

399
400
main()
Ques 231:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A LIST AND SEARCH THE
ELEMENT USING LINEAR SEARCH
Sol:
l=[ ]
def linsearch(s):
pos=-1
for i in range(len(l)):
if l [i]==s:
return i , True
return pos, False
def inputlist( ):
while True:
p=int(input("Enter any number"))
l.append(p)
ch=input("Do you want to enter more (y/n)")
if ch.upper( )=='Y':
continue
else:
break
def main( ):
print("Enter the value in list")
inputlist( )
print("The list is",l)
search=int(input("Enter the value you want to search"))
p,flag=linsearch(search)
if flag == True:
print("%d element is found in %d position"%(search,p+1))
else:
print("%d element is not found"%(search))

401
402
main( )
Ques 232: WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A LIST AND SEARCH THE
ELEMENT USING BINARY SEARCH TECHNIQUE
Sol:
l=[ ]
def inputlist():
while True:
p=int(input("Enter any value:"))
l.append(p)
ch=input("Do you want to enter more data(y/n)")
if ch.upper()=='Y':
continue
else:
break
def binsearch(s):
low=0
high=len(l)-1
while low<=high:
mid=(low+high)//2
if l [mid]>s:
high=mid-1
elif l[mid]<s:
low=mid+1
else:
return mid,True
if low>high:
return-1,False
def main( ):
print("Enter the value in the list")
inputlist( )
l.sort( )
403
print("The list is",l)
search=int(input("Enter the value you want to search"))
pos,flag=binsearch(search)
if flag==True:
print("%d is found in %d position"%(search,pos+1))
else:
print("%d is not found"%(search))
main( )

404
405
Ques 233 WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A LIST
AND FIND THE SECOND GREATEST ELEMENT WITHOUT SORTING
Sol:
def list():
l=[]
while True:
p=int(input("Enter the number:"))
l.append(p)
ch=input("Do you want to enter more (Y/n):")
if ch.upper()=='Y':
continue
else:
break
print("The list is",l)
large=slarge=l[0]
for i in range(1,len(l)):
if large<l[i]:
slarge=large
large=l[i]
elif large>l[i] and slarge<l[i]:
slarge=l[i]
print("The second largest number is",slarge)
def main():
list()
main()

406
407
main()
Ques 234: WRITE A PROGRAM IN PYTHON USING FUNCTION TO SHIFT THE RIGHT HALF ELEMENT TO LEFT
AND LEFT HALF ELEMENT TO RIGHT
Sol:
import math
l=[ ]
def listk():
k=math.ceil(len(l)/2)
for i in range(len(l)//2):
l[i],l[k+i]=l[k+i],l[i]
def inputlist( ):
while True:
n=int(input("Enter any number"))
l.append(n)
ch=input("Do you want to enter more data(y/n)")
if ch.upper()=='Y':
continue
else:
break
def main():
print("Enter the value in list")
inputlist( )
print("The list is",l)
listk()
print("The updated list is",l)
main()

408
409
main( )
Ques 235:WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT AND FIND
THE SECOND SMALLEST ELEMENT WITHOUT SHORTING
Sol:
l=[ ]
def list():
while True:
p=int(input("Enter the element:"))
l.append(p)
ch=input("Do you want to enter more data(Y/N):")
if ch.upper()=='Y':
continue
else:
break
def sm():
small=l[0]
ssmall=l[0]
for i in range(1,len(l)):
if small >l[i]:
ssmall=small
small=l[i]
elif l[i]>small and l[i]<ssmall:
ssmall=l[i]
print("The second smallest number is",ssmall)
def main():
print("enter value in list")
list()
print("the list is",l)
sm()
print("the second samllest element in a list is ",l)
main()

410
411
main()
Ques 236:WRITE A PROGRAM IN PYTHON USING FUNCTION TO SORT THE ELEMENT OF
A LIST USING BUBBLE SORT TECQUNIE
Sol:
l=[ ]
def bubb( ):
for i in range(len(l)-1):
for j in range(len(l)-i-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
def inputlist():
while True:
p=int(input("Enter any number"))
l.append(p)
ch=input("Do you want to enter more data(y/n)")
if ch.upper()=='Y':
continue
else:
break
def main():
print("Enter the value in list")
inputlist()
print("The list is",l)
bubb( )
print("The update list is",l)
main()

412
413
main( )
Ques 237:Write a program using function to do insertion sort
Sol:
l=[]
def inpu():
while True:
p=int(input("enter the element"))
l.append(p)
ch=input("DO YOU WANT TO ENTER MORE DATA(y/n)")
if ch.upper()=='Y':
continue
else:
break

def sot(l):
for i in range (1,len(l)):
value=l[i]
pos=i
while pos>0 and value<l[pos-1]:
l[pos]=l[pos-1]
pos-=1
l[pos]=value
return l
def main():
inpu()
print("The updated list is",l)
p=sot(l)
print("The sorted list is",p)
main()

414
415
Ques 238: WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE ADDITION OF
2 MATRICES
Sol:
def matin(A,m,n):
for i in range(m):
for j in range(n):
A[i][j]=int(input("enter the value in[%d] [%d] position"%(i,j)))
def matout(A,m,n):
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
def matpro(A,B,C,m,n):
for i in range(m):
for j in range(n):
C[i][j]=A[i][j]+B[i][j]
def main():
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
B=[[0 for col in range(n)]for row in range(m)]
C=[[0 for col in range(n)]for row in range(m)]
print("enter the value in 1st mqtrix")
matin(A,m,n)
print("-"*40)
print("enter the value in 2nd matrix")
matin(B,m,n)
print("-"*40)
matpro(A,B,C,m,n)
print("the 1st matrix is")
print("-"*40)
matout(A,m,n)
416
print("the second matrix is")
print("-"*40)
matout(B,m,n)
print("-"*40)
print("sum of the matrices are")
matout(C,m,n)
print("-"*40)
main()

417
Ques 239: WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE
SUBTRACTION OF 2 MATRICES
Sol:
def matin(A,m,n):
for i in range(m):
for j in range(n):
A[i][j]=int(input("enter the value in[%d] [%d] position"%(i,j)))
def matout(A,m,n):
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
def matpro(A,B,C,m,n):
for i in range(m):
for j in range(n):
C[i][j]=A[i][j]-B[i][j]
def main():
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
B=[[0 for col in range(n)]for row in range(m)]
C=[[0 for col in range(n)]for row in range(m)]
print("enter the value in 1st mqtrix")
matin(A,m,n)
print("-"*40)
print("enter the value in 2nd matrix")
matin(B,m,n)
print("-"*40)
matpro(A,B,C,m,n)
print("the 1st matrix is")
print("-"*40)
matout(A,m,n)
418
print("the second matrix is")
print("-"*40)
matout(B,m,n)
print("-"*40)
print("difference of the matrices are")
matout(C,m,n)
print("-"*40)
main()

419
Ques 240: WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE
MULTIPLICATION OF 2 MATRIX
Sol:
cation not possibel")
main()def matin(A, m, n):
for i in range(m):

for j in range(n):
A[i][j] = int(input("Enter the value in [%d] [%d] position: " % (i, j)))
def matout(A, m, n):
for i in range(m):
for j in range(n):

420
print("{0:^3}".format(A[i][j]), end=" ")
print()
def matpro(A, B, C, m, q, n):
for i in range(m):
for j in range(q):
C[i][j] = 0
for k in range(n):
C[i][j] += A[i][k] * B[k][j]
def main():
m = int(input("Enter the number of rows of the 1st matrix: "))
n = int(input("Enter the number of columns of the 1st matrix: "))
p = int(input("Enter the number of rows of the 2nd matrix: "))
q = int(input("Enter the number of columns of the 2nd matrix: "))
A = [[0 for col in range(n)] for row in range(m)]
B = [[0 for col in range(q)] for row in range(p)]
C = [[0 for col in range(q)] for row in range(m)]
print("Enter the values in the 1st matrix:")
matin(A, m, n)
print("Enter the values in the 2nd matrix:")
if n==p:
matin(B,p,q)
matpro(A, B, C, m, q, n)
print("The 1st matrix is:")
matout(A, m, n)
print("The 2nd matrix is:")
matout(B, p, q)
print("Product of the matrices is:")
matout(C, m, q)
else:
print("matrix multipli

421
Ques 241: WRITE A PROGRAM IN PYTHON USING FUNCTION TO TAKE INPUT IN A
matrix AND TRANSPOSE IT
Sol:
def matin(A,m,n):
for i in range(m):
for j in range(n):
A[i][j]=int(input("enter the value in [%d][%d] position"%(i,j)))
def matout(A,m,n):
for i in range(m):
for j in range(n):
print("{0:^3}".format(A[i][j]),end=" ")
print()
def matpro(A,m,n):
for i in range(n):
for j in range(m):
print("{0:^3}".format(A[j][i]),end=" ")
print()
def main():
m=int(input("Enter the number of rows of the matrix: "))
n=int(input("Enter the number of columns of the matrix: "))
A=[[0 for col in range(n)]for row in range(m)]
print("enter the value in 1st mqtrix")
matin(A,m,n)
print("-"*40)
print("the 1st matrix is")
print("-"*40)
matpro(A,m,n)
print("The transposed matrix is")
print("-"*40)
matout(A,m,n)
print("-"*40)
main()
422
423
main()

424
Ques 242: WRITE A PROGRAM IN PYTHON USING FUNCTION TO PRINT THE PRIMARY
AND SECONDARY DIAGONALS OF A SQUARE MATRIX
Sol:
def matin(A,m):
for i in range(m):
for j in range(m):
A[i][j]=int(input("enter the value in [%d][%d] position"%(i,j)))
def matout(A,m):
for i in range(m):
for j in range(m):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
def prim(A,m):
for i in range(m):
print(A[i][i],end=" ")
print()
def secon(A,m):
for j in range(m):
print(A[j] [m-j-1],end=" ")
print()
def main():
m=int(input("Enter the number of column/rows of the matrix: "))
A=[[0 for col in range(m)]for row in range(m)]
print("enter the value in 1st mqtrix")
matin(A,m)
print("-"*40)
matout(A,m)
print("-"*40)
prim(A,m)
print("-"*40)
secon(A,m)
425
print("-"*40)
main()

426
Ques 243:WRITE A PROGRAM IN PYTHON USING FUNCTION TO FIND THE SUM OF
PRIMARY AND SECONDARY DIAGONALS OF THE SQUARE MATRIX INDIVUSALLY
Sol:
def matin(A, m):
for i in range(m):
for j in range(m):
A[i][j] = int(input("Enter the value in [%d][%d] position: " % (i, j)))
def matout(A, m):
for i in range(m):
for j in range(m):
print("{0:^3}".format(A[i][j]), end=" ")
print()
def prim(A, m):
prim_sum = 0
sec_sum = 0
for i in range(m):
for j in range(m):
if i == j:
prim_sum += A[i][j]
if i + j == m - 1:
sec_sum += A[i][j]
print("Sum of primary diagonal:", prim_sum)
print("Sum of secondary diagonal:", sec_sum)
def main():
m = int(input("Enter the number of columns/rows of the matrix: "))
A = [[0 for col in range(m)] for row in range(m)]
print("Enter the values in the matrix:")
matin(A, m)
print("-" * 40)
matout(A, m)
print("-" * 40)
prim(A, m)
427
print("-" * 40)
main()

428
Ques 244: WRITE A PROGRAM IN PYTHON USING FUNCTION TO PRINT THE UPPER
HALF AND LOWER HALF OF THE SQUARE MATRIX
Sol:
def matin(A,m):
for i in range(m):
for j in range(m):
A[i][j]=int(input("enter the value in [%d][%d] position"%(i,j)))
def matout(A,m):
for i in range(m):
for j in range(m):
print("{0:^3}".format(A[i][j]),end=" ")
print()
print()
def uphalf(A,m):
for i in range (m):
for j in range (m-i):
print(A[i][j],end=" ")
print()
print("-"*40)
for i in range(m):
for j in range(i):
print(" ",end=" ")
for k in range(i,m):
print(A[i][k],end=" ")
print()
def lowhalf(A,m):
for i in range(m):
for j in range(i+1):
print(A[i][j],end=" ")
print()
print("-"*40)
for i in range(m):
429
for j in range(m):
if i+j>1:
print(A[i][j],end=" ")
else:
print(" ",end=" ")
print()
def main():
m=int(input("Enter the number of column/rows of the matrix: "))
A=[[0 for col in range(m)]for row in range(m)]
print("Enter the value in Matrix")
print("-"*40)
matin(A,m)
print("The matrix is")
print("-"*40)
matout(A,m)
print("Upper half of the matris is")
uphalf(A,m)
print("Lower half of the matrix is")
lowhalf(A,m)
main()

430
# create dictionary from two lists without losing duplicate values

from collections import defaultdict

class_list=['class-V','class-VI','class-VII','class-VIII']

id_list=[1,2,2,3]

temp=defaultdict(set)

for c,i in zip(class_list,id_list):

temp[c].add(i)

print(temp)

#concatenate dictionaries to create a new one

n=int(input("enter..."))

dic1={}

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

k=input("enter keys")

v=input("enter value")

dic1[k]=v

n=int(input("enter..."))

dic2={}

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

k=input("enter keys")

v=input("enter value")

dic2[k]=v

n=int(input("enter..."))

dic3={}

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

k=input("enter keys")

v=input("enter value")

dic3[k]=v

print(dic1)

print(dic2)

print(dic3)

dic4 = {}

for d in (dic1, dic2, dic3):

dic4.update(d)

print(dic4)

# dictionary in table format

my_dict = {'C1':[1,2,3],'C2':[5,6,7],'C3':[9,10,11]}

for row in zip(*([key] + (value) for key, value in sorted(my_dict.items()))):

print(*row)

# dictionary print line by line

students = {'Aex':{'class':'V',

432
'roll_id':2},

'Puja':{'class':'V',

'roll_id':3}}

for a in students:

print(a)

for b in students[a]:

print (b,':',students[a][b])

# sort a list alphabetically in a dictionary

num = {'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]}

sorted_dict = {x: sorted(y) for x, y in num.items()}

print(sorted_dict)

# sorting a dictionary after creating it

import operator

n=int(input("enter..."))

d={}

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

k=input("enter keys")

433
v=input("enter value")

d[k]=v

print("Original list is",d)

sorted_d = sorted(d.items(), key=operator.itemgetter(0))

print('Dictionary in ascending order by value : ',sorted_d)

sorted_d = dict( sorted(d.items(), key=operator.itemgetter(0),reverse=True))

print('Dictionary in descending order by value : ',sorted_d)

# sum of all items in a dictionary

my_dict = {'data1':100,'data2':-54,'data3':247}

print(sum(my_dict.values()))

n=int(input("enter no. of terms:"))

d={}

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

k=input("enter keys")

v=input("enter value")

d[k]=v

print('Original dictionary : ',d)

x=input("enter a key u want to del.")

if x in d:

del d[x]

print(d)

434
#print a dictionary in (x,x*x) form

n=int(input("Input a number "))

d = dict()

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

d[x]=x*x

print(d)

435

You might also like