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 diff --git a/exercises/Q3.py b/exercises/Q3.py new file mode 100644 index 00000000..80008b8a --- /dev/null +++ b/exercises/Q3.py @@ -0,0 +1,21 @@ +''' +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 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