From 00aada28c161af9e90c569f6479f92f9f8c62173 Mon Sep 17 00:00:00 2001 From: Mohanraj Periyasamy Date: Thu, 1 Nov 2018 06:13:04 +0800 Subject: [PATCH 1/4] add Q1.py --- exercises/Q1.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 exercises/Q1.py diff --git a/exercises/Q1.py b/exercises/Q1.py new file mode 100644 index 00000000..def12ab0 --- /dev/null +++ b/exercises/Q1.py @@ -0,0 +1,10 @@ +'''Question: +Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, +between 2000 and 3200 (both included). +The numbers obtained should be printed in a comma-separated sequence on a single line. + +Hints: +Consider use range(#begin, #end) method''' + +l = [x for x in range(2000, 3201) if x % 7 == 0 and x % 5 != 0] +print(l) \ No newline at end of file From b88740e27f40c8c1464b69973edd76621fd2e2ed Mon Sep 17 00:00:00 2001 From: Mohanraj Periyasamy Date: Thu, 1 Nov 2018 06:14:45 +0800 Subject: [PATCH 2/4] add Q3.py --- exercises/Q3.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 exercises/Q3.py diff --git a/exercises/Q3.py b/exercises/Q3.py new file mode 100644 index 00000000..2104fccd --- /dev/null +++ b/exercises/Q3.py @@ -0,0 +1,22 @@ +''' +Question 3 +Level 1 + +Question: +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. +Suppose the following input is supplied to the program: +8 +Then, the output should be: +{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64} + +''' + + +def integral(x): + + if x > 0 and isinstance(x, int): + return {y: y**2 for y in range(1, x+1)} + else: + return {0: 0} + +print(integral(8)) \ No newline at end of file From ae11489be11f6b8da59765b78ad93c13262e50d3 Mon Sep 17 00:00:00 2001 From: Mohanraj Periyasamy Date: Thu, 1 Nov 2018 06:21:20 +0800 Subject: [PATCH 3/4] add Q3.py --- exercises/Q3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/Q3.py b/exercises/Q3.py index 2104fccd..80008b8a 100644 --- a/exercises/Q3.py +++ b/exercises/Q3.py @@ -8,7 +8,6 @@ 8 Then, the output should be: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64} - ''' From c0bd9760f7a16db92ab197f15a2e9b4136e119fc Mon Sep 17 00:00:00 2001 From: Mohanraj Periyasamy Date: Wed, 7 Nov 2018 05:46:20 +0800 Subject: [PATCH 4/4] add Q3.py --- exercises/Q5.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 exercises/Q5.py diff --git a/exercises/Q5.py b/exercises/Q5.py new file mode 100644 index 00000000..14eecd7f --- /dev/null +++ b/exercises/Q5.py @@ -0,0 +1,30 @@ +''' +Question 5 +Level 1 + +Question: +Define a class which has at least two methods: +getString: to get a string from console input +printString: to print the string in upper case. +Also please include simple test function to test the class methods. + +Hints: +Use __init__ method to construct some parameters + + +''' + + +class InOutString(object): + def __init__(self): + self.str = "No Input Given" + + def getString(self): + self.str = input("Type something") + + def printString(self): + print(self.str) + +tst = InOutString() +tst.getString() +tst.printString() \ No newline at end of file