From 4b4c78271a1ac292ecfc875cf86ef9e17e380c6b Mon Sep 17 00:00:00 2001 From: Noor Faziur Reza Date: Wed, 17 Sep 2014 12:47:27 +0600 Subject: [PATCH 1/5] Update 100+ Python challenging programming exercises.txt --- 100+ Python challenging programming exercises.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 66c00215..c49b6270 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -34,6 +34,10 @@ for i in range(2000, 3201): l.append(str(i)) print ','.join(l) + +another solution using list comprehension: +a= [x for x in range(2000,3201) if (x%7==0 and x%5 != 0)] +print ','.join(str(x) for x in a) #----------------------------------------# #----------------------------------------# @@ -177,7 +181,7 @@ Level 2 Question: 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. -Note: i=0,1.., X-1; j=0,1,¡­Y-1. +Note: i=0,1.., X-1; j=0,1,¡­Y-1. Example Suppose the following inputs are given to the program: 3,5 @@ -225,7 +229,7 @@ print ','.join(items) Question 9 Level 2 -Question£º +Question£º Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized. Suppose the following input is supplied to the program: Hello world @@ -425,7 +429,7 @@ Question: 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: D 100 W 200 -¡­ +¡­ D means deposit while W means withdrawal. Suppose the following input is supplied to the program: D 300 @@ -568,13 +572,13 @@ for i in reverse(100): Question 21 Level 3 -Question£º +Question£º 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: UP 5 DOWN 3 LEFT 3 RIGHT 2 -¡­ +¡­ The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer. Example: If the following tuples are given as input to the program: From 27442f77ef68b7bc19c365efb1dd6f5e35b2fec5 Mon Sep 17 00:00:00 2001 From: Noor Faziur Reza Date: Wed, 17 Sep 2014 12:49:11 +0600 Subject: [PATCH 2/5] Update 100+ Python challenging programming exercises.txt --- 100+ Python challenging programming exercises.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index c49b6270..a6b8ff86 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -36,8 +36,8 @@ for i in range(2000, 3201): print ','.join(l) another solution using list comprehension: -a= [x for x in range(2000,3201) if (x%7==0 and x%5 != 0)] -print ','.join(str(x) for x in a) +l= [i for i in range(2000,3201) if (i%7==0 and i%5 != 0)] +print ','.join(str(i) for i in l) #----------------------------------------# #----------------------------------------# From d6efa76c6e8af63be3856c76ed885dc8ed11d0b8 Mon Sep 17 00:00:00 2001 From: Noor Faziur Reza Date: Tue, 30 Sep 2014 15:24:35 +0600 Subject: [PATCH 3/5] Update 100+ Python challenging programming exercises.txt --- 100+ Python challenging programming exercises.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index a6b8ff86..62762138 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -533,7 +533,8 @@ In case of input data being supplied to the question, it should be assumed to be We use itemgetter to enable multiple sort keys. Solutions: -from operator import itemgetter, attrgetter + +from operator import itemgetter, attrgetter l = [] while True: From 79b6fe7867dc4e9d8bcba9b0196a7d260660419b Mon Sep 17 00:00:00 2001 From: Noor Faziur Reza Date: Thu, 9 Oct 2014 16:01:29 +0600 Subject: [PATCH 4/5] Update 100+ Python challenging programming exercises.txt --- 100+ Python challenging programming exercises.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 62762138..c6d2236e 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -1101,7 +1101,7 @@ Use tuple() to generate a tuple from a list. Solution tp=(1,2,3,4,5,6,7,8,9,10) li=list() -for i in tp: +for i in range(0,len(tp)): if tp[i]%2==0: li.append(tp[i]) From a1de4d6a515187185b34a269ebb1f6d235351a9a Mon Sep 17 00:00:00 2001 From: Noor Faziur Reza Date: Sat, 29 Nov 2014 22:37:00 +0600 Subject: [PATCH 5/5] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..e821d3a8 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Python-programming-exercises +============================ + +100+ Python challenging programming exercises