Skip to content

Commit 3d7aea4

Browse files
authored
Update 100+ Python challenging programming exercises.txt
1 parent 1e8e42d commit 3d7aea4

File tree

1 file changed

+66
-31
lines changed

1 file changed

+66
-31
lines changed

100+ Python challenging programming exercises.txt

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ Question 3
7272
Level 1
7373

7474
Question:
75-
With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
75+
With a given integral number n, write a program to generate a dictionary that contains (i, i*i)
76+
such that is an integral number between 1 and n (both included). and then the program should print
77+
the dictionary.
7678
Suppose the following input is supplied to the program:
7779
8
7880
Then, the output should be:
@@ -96,7 +98,8 @@ Question 4
9698
Level 1
9799

98100
Question:
99-
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
101+
Write a program which accepts a sequence of comma-separated numbers from console and generate
102+
a list and a tuple which contains every number.
100103
Suppose the following input is supplied to the program:
101104
34,67,55,33,12,98
102105
Then, the output should be:
@@ -161,7 +164,8 @@ The output of the program should be:
161164
18,22,24
162165

163166
Hints:
164-
If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26)
167+
If the output received is in decimal form, it should be rounded off to its nearest value
168+
(for example, if the output received is 26.0, it should be printed as 26)
165169
In case of input data being supplied to the question, it should be assumed to be a console input.
166170

167171
Solution:
@@ -182,7 +186,8 @@ Question 7
182186
Level 2
183187

184188
Question:
185-
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
189+
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array.
190+
The element value in the i-th row and j-th column of the array should be i*j.
186191
Note: i=0,1.., X-1; j=0,1,¡­Y-1.
187192
Example
188193
Suppose the following inputs are given to the program:
@@ -191,7 +196,8 @@ Then, the output of the program should be:
191196
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
192197

193198
Hints:
194-
Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form.
199+
Note: In case of input data being supplied to the question, it should be assumed to be a console
200+
input in a comma-separated form.
195201

196202
Solution:
197203
input_str = raw_input()
@@ -212,7 +218,8 @@ Question 8
212218
Level 2
213219

214220
Question:
215-
Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
221+
Write a program that accepts a comma separated sequence of words as input and prints the words
222+
in a comma-separated sequence after sorting them alphabetically.
216223
Suppose the following input is supplied to the program:
217224
without,hello,bag,world
218225
Then, the output should be:
@@ -232,7 +239,8 @@ Question 9
232239
Level 2
233240

234241
Question£º
235-
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
242+
Write a program that accepts sequence of lines as input and prints the lines after making all
243+
characters in the sentence capitalized.
236244
Suppose the following input is supplied to the program:
237245
Hello world
238246
Practice makes perfect
@@ -261,7 +269,8 @@ Question 10
261269
Level 2
262270

263271
Question:
264-
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
272+
Write a program that accepts a sequence of whitespace separated words as input and prints
273+
the words after removing all duplicate words and sorting them alphanumerically.
265274
Suppose the following input is supplied to the program:
266275
hello world and practice makes perfect and hello world again
267276
Then, the output should be:
@@ -282,7 +291,9 @@ Question 11
282291
Level 2
283292

284293
Question:
285-
Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
294+
Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input
295+
and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are
296+
to be printed in a comma separated sequence.
286297
Example:
287298
0100,0011,1010,1001
288299
Then the output should be:
@@ -308,7 +319,8 @@ Question 12
308319
Level 2
309320

310321
Question:
311-
Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.
322+
Write a program, which will find all such numbers between 1000 and 3000 (both included) such that
323+
each digit of the number is an even number.
312324
The numbers obtained should be printed in a comma-separated sequence on a single line.
313325

314326
Hints:
@@ -357,7 +369,8 @@ Question 14
357369
Level 2
358370

359371
Question:
360-
Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.
372+
Write a program that accepts a sentence and calculate the number of upper case letters and
373+
lower case letters.
361374
Suppose the following input is supplied to the program:
362375
Hello world!
363376
Then, the output should be:
@@ -409,7 +422,8 @@ Question 16
409422
Level 2
410423

411424
Question:
412-
Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers.
425+
Use a list comprehension to square each odd number in a list. The list is input by a
426+
sequence of comma-separated numbers.
413427
Suppose the following input is supplied to the program:
414428
1,2,3,4,5,6,7,8,9
415429
Then, the output should be:
@@ -428,7 +442,8 @@ Question 17
428442
Level 2
429443

430444
Question:
431-
Write a program that computes the net amount of a bank account based a transaction log from console input. The transaction log format is shown as following:
445+
Write a program that computes the net amount of a bank account based a transaction
446+
log from console input. The transaction log format is shown as following:
432447
D 100
433448
W 200
434449

@@ -467,7 +482,8 @@ Question 18
467482
Level 3
468483

469484
Question:
470-
A website requires the users to input username and password to register. Write a program to check the validity of password input by users.
485+
A website requires the users to input username and password to register. Write a program to check
486+
the validity of password input by users.
471487
Following are the criteria for checking the password:
472488
1. At least 1 letter between [a-z]
473489
2. At least 1 number between [0-9]
@@ -515,7 +531,9 @@ Question 19
515531
Level 3
516532

517533
Question:
518-
You are required to write a program to sort the (name, age, height) tuples by ascending order where name is string, age and height are numbers. The tuples are input by console. The sort criteria is:
534+
You are required to write a program to sort the (name, age, height) tuples by ascending
535+
order where name is string, age and height are numbers. The tuples are input by console.
536+
The sort criteria is:
519537
1: Sort based on name;
520538
2: Then sort based on age;
521539
3: Then sort by score.
@@ -551,7 +569,8 @@ Question 20
551569
Level 3
552570

553571
Question:
554-
Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.
572+
Define a class with a generator which can iterate the numbers, which are divisible by 7,
573+
between a given range 0 and n.
555574

556575
Hints:
557576
Consider use yield
@@ -574,7 +593,8 @@ Question 21
574593
Level 3
575594

576595
Question£º
577-
A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following:
596+
A robot moves in a plane starting from the original point (0,0). The robot can move toward
597+
UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following:
578598
UP 5
579599
DOWN 3
580600
LEFT 3
@@ -622,7 +642,8 @@ Question 22
622642
Level 3
623643

624644
Question:
625-
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
645+
Write a program to compute the frequency of the words from the input. The output should output
646+
after sorting the key alphanumerically.
626647
Suppose the following input is supplied to the program:
627648
New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.
628649
Then, the output should be:
@@ -677,8 +698,10 @@ Question 24
677698
Level 1
678699

679700
Question:
680-
Python has many built-in functions, and if you do not know how to use it, you can read document online or find some books. But Python has a built-in document function for every built-in functions.
681-
Please write a program to print some Python built-in functions documents, such as abs(), int(), raw_input()
701+
Python has many built-in functions, and if you do not know how to use it, you can read
702+
document online or find some books. But Python has a built-in document function for every
703+
built-in functions. Please write a program to print some Python built-in functions documents,
704+
such as abs(), int(), raw_input()
682705
And add document for your own function
683706

684707
Hints:
@@ -733,7 +756,8 @@ Question:
733756
Define a function which can compute the sum of two numbers.
734757

735758
Hints:
736-
Define a function with two numbers as arguments. You can compute the sum in the function and return the value.
759+
Define a function with two numbers as arguments. You can compute the sum in the function
760+
and return the value.
737761

738762
Solution
739763
def SumFunction(number1, number2):
@@ -774,7 +798,8 @@ printValue(3)
774798
2.10
775799

776800
Question:
777-
Define a function that can receive two integral numbers in string form and compute their sum and then print it in console.
801+
Define a function that can receive two integral numbers in string form and compute their sum
802+
and then print it in console.
778803

779804
Hints:
780805

@@ -809,7 +834,9 @@ printValue("3","4") #34
809834

810835

811836
Question:
812-
Define a function that can accept two strings as input and print the string with maximum length in console. If two strings have the same length, then the function should print al l strings line by line.
837+
Define a function that can accept two strings as input and print the string with maximum
838+
length in console. If two strings have the same length, then the function should print all
839+
strings line by line.
813840

814841
Hints:
815842

@@ -836,7 +863,8 @@ printValue("one","three")
836863
2.10
837864

838865
Question:
839-
Define a function that can accept an integer number as input and print the "It is an even number" if the number is even, otherwise print "It is an odd number".
866+
Define a function that can accept an integer number as input and print the "It is an even number"
867+
if the number is even, otherwise print "It is an odd number".
840868

841869
Hints:
842870

@@ -857,7 +885,8 @@ checkValue(7)
857885
2.10
858886

859887
Question:
860-
Define a function which can print a dictionary where the keys are numbers between 1 and 3 (both included) and the values are square of keys.
888+
Define a function which can print a dictionary where the keys are numbers between
889+
1 and 3 (both included) and the values are square of keys.
861890

862891
Hints:
863892

@@ -883,7 +912,8 @@ printDict()
883912
2.10
884913

885914
Question:
886-
Define a function which can print a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys.
915+
Define a function which can print a dictionary where the keys are numbers between 1 and 20
916+
(both included) and the values are square of keys.
887917

888918
Hints:
889919

@@ -906,7 +936,8 @@ printDict()
906936
2.10
907937

908938
Question:
909-
Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys. The function should just print the values only.
939+
Define a function which can generate a dictionary where the keys are numbers between 1 and 20
940+
(both included) and the values are square of keys. The function should just print the values only.
910941

911942
Hints:
912943

@@ -930,7 +961,8 @@ printDict()
930961
2.10
931962

932963
Question:
933-
Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys. The function should just print the keys only.
964+
Define a function which can generate a dictionary where the keys are numbers between 1 and 20
965+
(both included) and the values are square of keys. The function should just print the keys only.
934966

935967
Hints:
936968

@@ -955,7 +987,8 @@ printDict()
955987
2.10
956988

957989
Question:
958-
Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).
990+
Define a function which can generate and print a list where the values are square of numbers
991+
between 1 and 20 (both included).
959992

960993
Hints:
961994

@@ -977,7 +1010,8 @@ printList()
9771010
2.10
9781011

9791012
Question:
980-
Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print the first 5 elements in the list.
1013+
Define a function which can generate a list where the values are square of numbers between
1014+
1 and 20 (both included). Then the function needs to print the first 5 elements in the list.
9811015

9821016
Hints:
9831017

@@ -1001,7 +1035,8 @@ printList()
10011035
2.10
10021036

10031037
Question:
1004-
Define a function which can generate a list where the values are square of numbers between 1 and 20 (both included). Then the function needs to print the last 5 elements in the list.
1038+
Define a function which can generate a list where the values are square of numbers between
1039+
1 and 20 (both included). Then the function needs to print the last 5 elements in the list.
10051040

10061041
Hints:
10071042

0 commit comments

Comments
 (0)