100 Python Programs
100 Python Programs
php
1 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
2 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
4 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
[1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3]
Output:
False
Input:
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
Output:
False
Click me to see the sample solution (python-programming-puzzles-9.php)
5 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
[False, True, True, False, False]
Click me to see the sample solution (python-programming-puzzles-12.php)
6 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
7 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
8 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
[19, 19, 5, 5, 5, 5, 5]
Output:
Not a monotonic sequence!
Click me to see the sample solution (python-programming-puzzles-20.php)
9 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
[6, 5, 4, 3, 2, 1]
Output:
[1, 2, 3, 4, 5]
Input:
[1, 19, 5, 15, 5, 25, 5]
Output:
[0, 2, 4, 6]
Click me to see the sample solution (python-programming-puzzles-23.php)
Write a Python program to create a list whose ith element is the maximum
of the first i elements from an input list.
Input:
[0, -1, 3, 8, 5, 9, 8, 14, 2, 4, 3, -10, 10, 17, 41, 22, -4, -4, -15, 0]
Output:
[0, 0, 3, 8, 8, 9, 9, 14, 14, 14, 14, 14, 14, 17, 41, 41, 41, 41, 41, 41]
Input:
[6, 5, 4, 3, 2, 1]
Output:
[6, 6, 6, 6, 6, 6]
Input:
[1, 19, 5, 15, 5, 25, 5]
Output:
[1, 19, 19, 19, 19, 25, 25]
Click me to see the sample solution (python-programming-puzzles-24.php)
10 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
['100', '102,1', '101.1']
Output:
102.1
Click me to see the sample solution (python-programming-puzzles-26.php)
11 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
[1, 7]
Click me to see the sample solution (python-programming-puzzles-29.php)
12 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
13 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
0
Input: 13579
Output:
945
Click me to see the sample solution (python-programming-puzzles-35.php)
14 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
500
Input: 6500
Output:
3250
Click me to see the sample solution (python-programming-puzzles-37.php)
15 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input: AEIOU
Output:
cgkqw
Click me to see the sample solution (python-programming-puzzles-40.php)
16 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
['time']
Number of consonants: 1
Words in the said string with 1 consonants:
['is', 'our']
Click me to see the sample solution (python-programming-puzzles-43.php)
17 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
[1, 9, 4, 6, 10, 11, 14, 8]
Output:
Minimum even value and its index of the said array of numbers:
[4, 2]
Input:
[1, 7, 4, 4, 9, 2]
Output:
Minimum even value and its index of the said array of numbers:
[2, 5]
Input:
[1, 7, 7, 5, 9]
Output:
Minimum even value and its index of the said array of numbers:
[]
Click me to see the sample solution (python-programming-puzzles-46.php)
18 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
[1, 2, 3, 4, 5, 6]
Output:
[]
Input:
[1, 2, 3, 4, 6, 5, 7]
Output:
[4, 5]
Input:
[-3, -2, -3, 0, 2, 3, 4]
Output:
[1, 2]
Click me to see the sample solution (python-programming-puzzles-48.php)
19 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Find the even-length words and sort them by length in the said list of
words:
['!!', 'bird', 'that', 'worm', 'Absurd']
Click me to see the sample solution (python-programming-puzzles-50.php)
20 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
21 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
22 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
[-25, -12, -23]
Output:
-60
Click me to see the sample solution (python-programming-puzzles-57.php)
Output:
['No', 'Yes', 'No', 'No', 'No']
Click me to see the sample solution (python-programming-puzzles-59.php)
24 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
25 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
Result = 23451
Input:
n = 12345 and shift = 2
Output:
Result = 34512
Input:
n = 12345 and shift = 3
Output:
Result = 45123
Input:
n = 12345 and shift = 5
Output:
Result = 12345
Input:
n = 12345 and shift = 6
Output:
Result = 54321
Click me to see the sample solution (python-programming-puzzles-65.php)
26 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
28 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input: Hello
Output:
Hel
Input: Sandwhich
Output:
San
Input: Python
Output:
hon
Click me to see the sample solution (python-programming-puzzles-73.php)
29 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
[9, 7, 6, 5, 4, 2, 1]
Click me to see the sample solution (python-programming-puzzles-75.php)
GPAs Grades
4.0: A+
3.7: A
3.4: A-
3.0: B+
2.7: B
2.4: B-
2.0: C+
1.7: C
1.4: C-
below: F
Input:
[4.0, 3.5, 3.8]
Output:
30 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Output:
['A+', 'A-', 'A']
Input:
[5.0, 4.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]
Output:
['A+', 'A+', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']
Click me to see the sample solution (python-programming-puzzles-77.php)
31 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
32 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
33 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
34 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Input:
Number of even digits: 4 ,Number of odd digits: 7
Output:
22223333333
Click me to see the sample solution (python-programming-puzzles-88.php)
35 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
Write a Python program to find all n-digit integers that start or end with 2.
Input: 1
Output:
[2]
Input: 2
Output:
[12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 42, 52, 62, 72, 82, 92]
Input: 3
Output:
[102, 112, 122, 132, 142, 152, 162, 172, 182, 192, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278,
279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 302, 312, 322, 332, 342, 352, 362, 372, 382,
392, 402, 412, 422, 432, 442, 452, 462, 472, 482, 492, 502, 512, 522, 532,
542, 552, 562, 572, 582, 592, 602, 612, 622, 632, 642, 652, 662, 672, 682,
692, 702, 712, 722, 732, 742, 752, 762, 772, 782, 792, 802, 812, 822, 832,
842, 852, 862, 872, 882, 892, 902, 912, 922, 932, 942, 952, 962, 972, 982,
992]
Click me to see the sample solution (python-programming-puzzles-91.php)
36 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
[8, 0, 7, 2, 9, 4, 1, 2, 8, 3]
Output:
[1, 0, 7, 2, 8, 4, 8, 2, 9, 3]
Click me to see the sample solution (python-programming-puzzles-92.php)
37 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
() (( ( )() ( )) ) ( ())
Output:
['()', '((()()()))', '(())']
Click me to see the sample solution (python-programming-puzzles-94.php)
39 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
40 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
More to Come !
Do not submit any solution of the above exercises at here, if you want
to contribute go to the appropriate exercise page.
It will be nice if you may share this link in any developer community or anywhere
41 of 42 12/14/2024, 8:43 PM
Python Programming Puzzles - Exercises, Practice, Solution - w3resource https://www.w3resource.com/python-exercises/puzzles/index.php
t will be nice if you may share this link in any developer community or anywhere
else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/puzzles/index.php
42 of 42 12/14/2024, 8:43 PM