diff --git a/100 Python Practice Problems.docx b/100 Python Practice Problems.docx new file mode 100644 index 00000000..163266d0 Binary files /dev/null and b/100 Python Practice Problems.docx differ diff --git a/100 Python Practice Problems.pdf b/100 Python Practice Problems.pdf new file mode 100644 index 00000000..06fdda38 Binary files /dev/null and b/100 Python Practice Problems.pdf differ diff --git a/100+ Python challenging programming exercises for Python 3.md b/100+ Python challenging programming exercises for Python 3.md index c4ba62c4..85de25a5 100644 --- a/100+ Python challenging programming exercises for Python 3.md +++ b/100+ Python challenging programming exercises for Python 3.md @@ -249,7 +249,7 @@ while True: if s: lines.append(s.upper()) else: - break; + break for sentence in lines: print(sentence) @@ -1080,7 +1080,7 @@ Use if statement to judge condition. Solution ```python -s= raw_input() +s= input() if s=="yes" or s=="YES" or s=="Yes": print "Yes" else: diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt deleted file mode 100644 index 97af5aaf..00000000 --- a/100+ Python challenging programming exercises.txt +++ /dev/null @@ -1,2375 +0,0 @@ -100+ Python challenging programming exercises - -1. Level description -Level Description -Level 1 Beginner means someone who has just gone through an introductory Python course. He can solve some problems with 1 or 2 Python classes or functions. Normally, the answers could directly be found in the textbooks. -Level 2 Intermediate means someone who has just learned Python, but already has a relatively strong programming background from before. He should be able to solve problems which may involve 3 or 3 Python classes or functions. The answers cannot be directly be found in the textbooks. -Level 3 Advanced. He should use Python to solve more complex problem using more rich libraries functions and data structures and algorithms. He is supposed to solve the problem using several Python standard packages and advanced techniques. - -2. Problem template - -#----------------------------------------# -Question -Hints -Solution - -3. Questions - -#----------------------------------------# -Question 1 -Level 1 - -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 - -Solution: -l=[] -for i in range(2000, 3201): - if (i%7==0) and (i%5!=0): - l.append(str(i)) - -print ','.join(l) -#----------------------------------------# - -#----------------------------------------# -Question 2 -Level 1 - -Question: -Write a program which can compute the factorial of a given numbers. -The results should be printed in a comma-separated sequence on a single line. -Suppose the following input is supplied to the program: -8 -Then, the output should be: -40320 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -def fact(x): - if x == 0: - return 1 - return x * fact(x - 1) - -x=int(raw_input()) -print fact(x) -#----------------------------------------# - -#----------------------------------------# -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} - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. -Consider use dict() - -Solution: -n=int(raw_input()) -d=dict() -for i in range(1,n+1): - d[i]=i*i - -print d -#----------------------------------------# - -#----------------------------------------# -Question 4 -Level 1 - -Question: -Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number. -Suppose the following input is supplied to the program: -34,67,55,33,12,98 -Then, the output should be: -['34', '67', '55', '33', '12', '98'] -('34', '67', '55', '33', '12', '98') - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. -tuple() method can convert list to tuple - -Solution: -values=raw_input() -l=values.split(",") -t=tuple(l) -print l -print t -#----------------------------------------# - -#----------------------------------------# -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 - -Solution: -class InputOutString(object): - def __init__(self): - self.s = "" - - def getString(self): - self.s = raw_input() - - def printString(self): - print self.s.upper() - -strObj = InputOutString() -strObj.getString() -strObj.printString() -#----------------------------------------# - -#----------------------------------------# -Question 6 -Level 2 - -Question: -Write a program that calculates and prints the value according to the given formula: -Q = Square root of [(2 * C * D)/H] -Following are the fixed values of C and H: -C is 50. H is 30. -D is the variable whose values should be input to your program in a comma-separated sequence. -Example -Let us assume the following comma separated input sequence is given to the program: -100,150,180 -The output of the program should be: -18,22,24 - -Hints: -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) -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -#!/usr/bin/env python -import math -c=50 -h=30 -value = [] -items=[x for x in raw_input().split(',')] -for d in items: - value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) - -print ','.join(value) -#----------------------------------------# - -#----------------------------------------# -Question 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. -Example -Suppose the following inputs are given to the program: -3,5 -Then, the output of the program should be: -[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] - -Hints: -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. - -Solution: -input_str = raw_input() -dimensions=[int(x) for x in input_str.split(',')] -rowNum=dimensions[0] -colNum=dimensions[1] -multilist = [[0 for col in range(colNum)] for row in range(rowNum)] - -for row in range(rowNum): - for col in range(colNum): - multilist[row][col]= row*col - -print multilist -#----------------------------------------# - -#----------------------------------------# -Question 8 -Level 2 - -Question: -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. -Suppose the following input is supplied to the program: -without,hello,bag,world -Then, the output should be: -bag,hello,without,world - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -items=[x for x in raw_input().split(',')] -items.sort() -print ','.join(items) -#----------------------------------------# - -#----------------------------------------# -Question 9 -Level 2 - -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 -Practice makes perfect -Then, the output should be: -HELLO WORLD -PRACTICE MAKES PERFECT - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -lines = [] -while True: - s = raw_input() - if s: - lines.append(s.upper()) - else: - break; - -for sentence in lines: - print sentence -#----------------------------------------# - -#----------------------------------------# -Question 10 -Level 2 - -Question: -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. -Suppose the following input is supplied to the program: -hello world and practice makes perfect and hello world again -Then, the output should be: -again and hello makes perfect practice world - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. -We use set container to remove duplicated data automatically and then use sorted() to sort the data. - -Solution: -s = raw_input() -words = [word for word in s.split(" ")] -print " ".join(sorted(list(set(words)))) -#----------------------------------------# - -#----------------------------------------# -Question 11 -Level 2 - -Question: -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. -Example: -0100,0011,1010,1001 -Then the output should be: -1010 -Notes: Assume the data is input by console. - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -value = [] -items=[x for x in raw_input().split(',')] -for p in items: - intp = int(p, 2) - if not intp%5: - value.append(p) - -print ','.join(value) -#----------------------------------------# - -#----------------------------------------# -Question 12 -Level 2 - -Question: -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. -The numbers obtained should be printed in a comma-separated sequence on a single line. - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -values = [] -for i in range(1000, 3001): - s = str(i) - if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0) and (int(s[3])%2==0): - values.append(s) -print ",".join(values) -#----------------------------------------# - -#----------------------------------------# -Question 13 -Level 2 - -Question: -Write a program that accepts a sentence and calculate the number of letters and digits. -Suppose the following input is supplied to the program: -hello world! 123 -Then, the output should be: -LETTERS 10 -DIGITS 3 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -s = raw_input() -d={"DIGITS":0, "LETTERS":0} -for c in s: - if c.isdigit(): - d["DIGITS"]+=1 - elif c.isalpha(): - d["LETTERS"]+=1 - else: - pass -print "LETTERS", d["LETTERS"] -print "DIGITS", d["DIGITS"] -#----------------------------------------# - -#----------------------------------------# -Question 14 -Level 2 - -Question: -Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters. -Suppose the following input is supplied to the program: -Hello world! -Then, the output should be: -UPPER CASE 1 -LOWER CASE 9 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -s = raw_input() -d={"UPPER CASE":0, "LOWER CASE":0} -for c in s: - if c.isupper(): - d["UPPER CASE"]+=1 - elif c.islower(): - d["LOWER CASE"]+=1 - else: - pass -print "UPPER CASE", d["UPPER CASE"] -print "LOWER CASE", d["LOWER CASE"] -#----------------------------------------# - -#----------------------------------------# -Question 15 -Level 2 - -Question: -Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a. -Suppose the following input is supplied to the program: -9 -Then, the output should be: -11106 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -a = raw_input() -n1 = int( "%s" % a ) -n2 = int( "%s%s" % (a,a) ) -n3 = int( "%s%s%s" % (a,a,a) ) -n4 = int( "%s%s%s%s" % (a,a,a,a) ) -print n1+n2+n3+n4 -#----------------------------------------# - -#----------------------------------------# -Question 16 -Level 2 - -Question: -Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers. -Suppose the following input is supplied to the program: -1,2,3,4,5,6,7,8,9 -Then, the output should be: -1,3,5,7,9 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -values = raw_input() -numbers = [x for x in values.split(",") if int(x)%2!=0] -print ",".join(numbers) -#----------------------------------------# - -Question 17 -Level 2 - -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 -D 300 -W 200 -D 100 -Then, the output should be: -500 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: -netAmount = 0 -while True: - s = raw_input() - if not s: - break - values = s.split(" ") - operation = values[0] - amount = int(values[1]) - if operation=="D": - netAmount+=amount - elif operation=="W": - netAmount-=amount - else: - pass -print netAmount -#----------------------------------------# - -#----------------------------------------# -Question 18 -Level 3 - -Question: -A website requires the users to input username and password to register. Write a program to check the validity of password input by users. -Following are the criteria for checking the password: -1. At least 1 letter between [a-z] -2. At least 1 number between [0-9] -1. At least 1 letter between [A-Z] -3. At least 1 character from [$#@] -4. Minimum length of transaction password: 6 -5. Maximum length of transaction password: 12 -Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. -Example -If the following passwords are given as input to the program: -ABd1234@1,a F1#,2w3E*,2We3345 -Then, the output of the program should be: -ABd1234@1 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solutions: -import re -value = [] -items=[x for x in raw_input().split(',')] -for p in items: - if len(p)<6 or len(p)>12: - continue - else: - pass - if not re.search("[a-z]",p): - continue - elif not re.search("[0-9]",p): - continue - elif not re.search("[A-Z]",p): - continue - elif not re.search("[$#@]",p): - continue - elif re.search("\s",p): - continue - else: - pass - value.append(p) -print ",".join(value) -#----------------------------------------# - -#----------------------------------------# -Question 19 -Level 3 - -Question: -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: -1: Sort based on name; -2: Then sort based on age; -3: Then sort by score. -The priority is that name > age > score. -If the following tuples are given as input to the program: -Tom,19,80 -John,20,90 -Jony,17,91 -Jony,17,93 -Json,21,85 -Then, the output of the program should be: -[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')] - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. -We use itemgetter to enable multiple sort keys. - -Solutions: -from operator import itemgetter, attrgetter - -l = [] -while True: - s = raw_input() - if not s: - break - l.append(tuple(s.split(","))) - -print sorted(l, key=itemgetter(0,1,2)) -#----------------------------------------# - -#----------------------------------------# -Question 20 -Level 3 - -Question: -Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n. - -Hints: -Consider use yield - -Solution: -def putNumbers(n): - i = 0 - while ilen2: - print s1 - elif len2>len1: - print s2 - else: - print s1 - print s2 - - -printValue("one","three") - - - -#----------------------------------------# -2.10 - -Question: -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". - -Hints: - -Use % operator to check if a number is even or odd. - -Solution -def checkValue(n): - if n%2 == 0: - print "It is an even number" - else: - print "It is an odd number" - - -checkValue(7) - - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use dict[key]=value pattern to put entry into a dictionary. -Use ** operator to get power of a number. - -Solution -def printDict(): - d=dict() - d[1]=1 - d[2]=2**2 - d[3]=3**2 - print d - - -printDict() - - - - - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use dict[key]=value pattern to put entry into a dictionary. -Use ** operator to get power of a number. -Use range() for loops. - -Solution -def printDict(): - d=dict() - for i in range(1,21): - d[i]=i**2 - print d - - -printDict() - - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use dict[key]=value pattern to put entry into a dictionary. -Use ** operator to get power of a number. -Use range() for loops. -Use keys() to iterate keys in the dictionary. Also we can use item() to get key/value pairs. - -Solution -def printDict(): - d=dict() - for i in range(1,21): - d[i]=i**2 - for (k,v) in d.items(): - print v - - -printDict() - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use dict[key]=value pattern to put entry into a dictionary. -Use ** operator to get power of a number. -Use range() for loops. -Use keys() to iterate keys in the dictionary. Also we can use item() to get key/value pairs. - -Solution -def printDict(): - d=dict() - for i in range(1,21): - d[i]=i**2 - for k in d.keys(): - print k - - -printDict() - - -#----------------------------------------# -2.10 - -Question: -Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included). - -Hints: - -Use ** operator to get power of a number. -Use range() for loops. -Use list.append() to add values into a list. - -Solution -def printList(): - li=list() - for i in range(1,21): - li.append(i**2) - print li - - -printList() - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use ** operator to get power of a number. -Use range() for loops. -Use list.append() to add values into a list. -Use [n1:n2] to slice a list - -Solution -def printList(): - li=list() - for i in range(1,21): - li.append(i**2) - print li[:5] - - -printList() - - -#----------------------------------------# -2.10 - -Question: -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. - -Hints: - -Use ** operator to get power of a number. -Use range() for loops. -Use list.append() to add values into a list. -Use [n1:n2] to slice a list - -Solution -def printList(): - li=list() - for i in range(1,21): - li.append(i**2) - print li[-5:] - - -printList() - - -#----------------------------------------# -2.10 - -Question: -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 all values except the first 5 elements in the list. - -Hints: - -Use ** operator to get power of a number. -Use range() for loops. -Use list.append() to add values into a list. -Use [n1:n2] to slice a list - -Solution -def printList(): - li=list() - for i in range(1,21): - li.append(i**2) - print li[5:] - - -printList() - - -#----------------------------------------# -2.10 - -Question: -Define a function which can generate and print a tuple where the value are square of numbers between 1 and 20 (both included). - -Hints: - -Use ** operator to get power of a number. -Use range() for loops. -Use list.append() to add values into a list. -Use tuple() to get a tuple from a list. - -Solution -def printTuple(): - li=list() - for i in range(1,21): - li.append(i**2) - print tuple(li) - -printTuple() - - - -#----------------------------------------# -2.10 - -Question: -With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line and the last half values in one line. - -Hints: - -Use [n1:n2] notation to get a slice from a tuple. - -Solution -tp=(1,2,3,4,5,6,7,8,9,10) -tp1=tp[:5] -tp2=tp[5:] -print tp1 -print tp2 - - -#----------------------------------------# -2.10 - -Question: -Write a program to generate and print another tuple whose values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10). - -Hints: - -Use "for" to iterate the tuple -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: - if tp[i]%2==0: - li.append(tp[i]) - -tp2=tuple(li) -print tp2 - - - -#----------------------------------------# -2.14 - -Question: -Write a program which accepts a string as input to print "Yes" if the string is "yes" or "YES" or "Yes", otherwise print "No". - -Hints: - -Use if statement to judge condition. - -Solution -s= raw_input() -if s=="yes" or s=="YES" or s=="Yes": - print "Yes" -else: - print "No" - - - -#----------------------------------------# -3.4 - -Question: -Write a program which can filter even numbers in a list by using filter function. The list is: [1,2,3,4,5,6,7,8,9,10]. - -Hints: - -Use filter() to filter some elements in a list. -Use lambda to define anonymous functions. - -Solution -li = [1,2,3,4,5,6,7,8,9,10] -evenNumbers = filter(lambda x: x%2==0, li) -print evenNumbers - - -#----------------------------------------# -3.4 - -Question: -Write a program which can map() to make a list whose elements are square of elements in [1,2,3,4,5,6,7,8,9,10]. - -Hints: - -Use map() to generate a list. -Use lambda to define anonymous functions. - -Solution -li = [1,2,3,4,5,6,7,8,9,10] -squaredNumbers = map(lambda x: x**2, li) -print squaredNumbers - -#----------------------------------------# -3.5 - -Question: -Write a program which can map() and filter() to make a list whose elements are square of even number in [1,2,3,4,5,6,7,8,9,10]. - -Hints: - -Use map() to generate a list. -Use filter() to filter elements of a list. -Use lambda to define anonymous functions. - -Solution -li = [1,2,3,4,5,6,7,8,9,10] -evenNumbers = map(lambda x: x**2, filter(lambda x: x%2==0, li)) -print evenNumbers - - - - -#----------------------------------------# -3.5 - -Question: -Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both included). - -Hints: - -Use filter() to filter elements of a list. -Use lambda to define anonymous functions. - -Solution -evenNumbers = filter(lambda x: x%2==0, range(1,21)) -print evenNumbers - - -#----------------------------------------# -3.5 - -Question: -Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included). - -Hints: - -Use map() to generate a list. -Use lambda to define anonymous functions. - -Solution -squaredNumbers = map(lambda x: x**2, range(1,21)) -print squaredNumbers - - - - -#----------------------------------------# -7.2 - -Question: -Define a class named American which has a static method called printNationality. - -Hints: - -Use @staticmethod decorator to define class static method. - -Solution -class American(object): - @staticmethod - def printNationality(): - print "America" - -anAmerican = American() -anAmerican.printNationality() -American.printNationality() - - - - -#----------------------------------------# - -7.2 - -Question: -Define a class named American and its subclass NewYorker. - -Hints: - -Use class Subclass(ParentClass) to define a subclass. - -Solution: - -class American(object): - pass - -class NewYorker(American): - pass - -anAmerican = American() -aNewYorker = NewYorker() -print anAmerican -print aNewYorker - - - - -#----------------------------------------# - - -7.2 - -Question: -Define a class named Circle which can be constructed by a radius. The Circle class has a method which can compute the area. - -Hints: - -Use def methodName(self) to define a method. - -Solution: - -class Circle(object): - def __init__(self, r): - self.radius = r - - def area(self): - return self.radius**2*3.14 - -aCircle = Circle(2) -print aCircle.area() - - - - - - -#----------------------------------------# - -7.2 - -Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a method which can compute the area. - -Hints: - -Use def methodName(self) to define a method. - -Solution: - -class Rectangle(object): - def __init__(self, l, w): - self.length = l - self.width = w - - def area(self): - return self.length*self.width - -aRectangle = Rectangle(2,10) -print aRectangle.area() - - - - -#----------------------------------------# - -7.2 - -Define a class named Shape and its subclass Square. The Square class has an init function which takes a length as argument. Both classes have a area function which can print the area of the shape where Shape's area is 0 by default. - -Hints: - -To override a method in super class, we can define a method with the same name in the super class. - -Solution: - -class Shape(object): - def __init__(self): - pass - - def area(self): - return 0 - -class Square(Shape): - def __init__(self, l): - Shape.__init__(self) - self.length = l - - def area(self): - return self.length*self.length - -aSquare= Square(3) -print aSquare.area() - - - - - - - - -#----------------------------------------# - - -Please raise a RuntimeError exception. - -Hints: - -Use raise() to raise an exception. - -Solution: - -raise RuntimeError('something wrong') - - - -#----------------------------------------# -Write a function to compute 5/0 and use try/except to catch the exceptions. - -Hints: - -Use try/except to catch exceptions. - -Solution: - -def throws(): - return 5/0 - -try: - throws() -except ZeroDivisionError: - print "division by zero!" -except Exception, err: - print 'Caught an exception' -finally: - print 'In finally block for cleanup' - - -#----------------------------------------# -Define a custom exception class which takes a string message as attribute. - -Hints: - -To define a custom exception, we need to define a class inherited from Exception. - -Solution: - -class MyError(Exception): - """My own exception class - - Attributes: - msg -- explanation of the error - """ - - def __init__(self, msg): - self.msg = msg - -error = MyError("something wrong") - -#----------------------------------------# -Question: - -Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the user name of a given email address. Both user names and company names are composed of letters only. - -Example: -If the following email address is given as input to the program: - -john@google.com - -Then, the output of the program should be: - -john - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: - -Use \w to match letters. - -Solution: -import re -emailAddress = raw_input() -pat2 = "(\w+)@((\w+\.)+(com))" -r2 = re.match(pat2,emailAddress) -print r2.group(1) - - -#----------------------------------------# -Question: - -Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only. - -Example: -If the following email address is given as input to the program: - -john@google.com - -Then, the output of the program should be: - -google - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: - -Use \w to match letters. - -Solution: -import re -emailAddress = raw_input() -pat2 = "(\w+)@(\w+)\.(com)" -r2 = re.match(pat2,emailAddress) -print r2.group(2) - - - - -#----------------------------------------# -Question: - -Write a program which accepts a sequence of words separated by whitespace as input to print the words composed of digits only. - -Example: -If the following words is given as input to the program: - -2 cats and 3 dogs. - -Then, the output of the program should be: - -['2', '3'] - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: - -Use re.findall() to find all substring using regex. - -Solution: -import re -s = raw_input() -print re.findall("\d+",s) - - -#----------------------------------------# -Question: - - -Print a unicode string "hello world". - -Hints: - -Use u'strings' format to define unicode string. - -Solution: - -unicodeString = u"hello world!" -print unicodeString - -#----------------------------------------# -Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8. - -Hints: - -Use unicode() function to convert. - -Solution: - -s = raw_input() -u = unicode( s ,"utf-8") -print u - -#----------------------------------------# -Question: - -Write a special comment to indicate a Python source code file is in unicode. - -Hints: - -Solution: - -# -*- coding: utf-8 -*- - -#----------------------------------------# -Question: - -Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0). - -Example: -If the following n is given as input to the program: - -5 - -Then, the output of the program should be: - -3.55 - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: -Use float() to convert an integer to a float - -Solution: - -n=int(raw_input()) -sum=0.0 -for i in range(1,n+1): - sum += float(float(i)/(i+1)) -print sum - - -#----------------------------------------# -Question: - -Write a program to compute: - -f(n)=f(n-1)+100 when n>0 -and f(0)=1 - -with a given n input by console (n>0). - -Example: -If the following n is given as input to the program: - -5 - -Then, the output of the program should be: - -500 - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: -We can define recursive function in Python. - -Solution: - -def f(n): - if n==0: - return 0 - else: - return f(n-1)+100 - -n=int(raw_input()) -print f(n) - -#----------------------------------------# - -Question: - - -The Fibonacci Sequence is computed based on the following formula: - - -f(n)=0 if n=0 -f(n)=1 if n=1 -f(n)=f(n-1)+f(n-2) if n>1 - -Please write a program to compute the value of f(n) with a given n input by console. - -Example: -If the following n is given as input to the program: - -7 - -Then, the output of the program should be: - -13 - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Hints: -We can define recursive function in Python. - - -Solution: - -def f(n): - if n == 0: return 0 - elif n == 1: return 1 - else: return f(n-1)+f(n-2) - -n=int(raw_input()) -print f(n) - - -#----------------------------------------# - -#----------------------------------------# - -Question: - -The Fibonacci Sequence is computed based on the following formula: - - -f(n)=0 if n=0 -f(n)=1 if n=1 -f(n)=f(n-1)+f(n-2) if n>1 - -Please write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console. - -Example: -If the following n is given as input to the program: - -7 - -Then, the output of the program should be: - -0,1,1,2,3,5,8,13 - - -Hints: -We can define recursive function in Python. -Use list comprehension to generate a list from an existing list. -Use string.join() to join a list of strings. - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: - -def f(n): - if n == 0: return 0 - elif n == 1: return 1 - else: return f(n-1)+f(n-2) - -n=int(raw_input()) -values = [str(f(x)) for x in range(0, n+1)] -print ",".join(values) - - -#----------------------------------------# - -Question: - -Please write a program using generator to print the even numbers between 0 and n in comma separated form while n is input by console. - -Example: -If the following n is given as input to the program: - -10 - -Then, the output of the program should be: - -0,2,4,6,8,10 - -Hints: -Use yield to produce the next value in generator. - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: - -def EvenGenerator(n): - i=0 - while i<=n: - if i%2==0: - yield i - i+=1 - - -n=int(raw_input()) -values = [] -for i in EvenGenerator(n): - values.append(str(i)) - -print ",".join(values) - - -#----------------------------------------# - -Question: - -Please write a program using generator to print the numbers which can be divisible by 5 and 7 between 0 and n in comma separated form while n is input by console. - -Example: -If the following n is given as input to the program: - -100 - -Then, the output of the program should be: - -0,35,70 - -Hints: -Use yield to produce the next value in generator. - -In case of input data being supplied to the question, it should be assumed to be a console input. - -Solution: - -def NumGenerator(n): - for i in range(n+1): - if i%5==0 and i%7==0: - yield i - -n=int(raw_input()) -values = [] -for i in NumGenerator(n): - values.append(str(i)) - -print ",".join(values) - - -#----------------------------------------# - -Question: - - -Please write assert statements to verify that every number in the list [2,4,6,8] is even. - - - -Hints: -Use "assert expression" to make assertion. - - -Solution: - -li = [2,4,6,8] -for i in li: - assert i%2==0 - - -#----------------------------------------# -Question: - -Please write a program which accepts basic mathematic expression from console and print the evaluation result. - -Example: -If the following string is given as input to the program: - -35+3 - -Then, the output of the program should be: - -38 - -Hints: -Use eval() to evaluate an expression. - - -Solution: - -expression = raw_input() -print eval(expression) - - -#----------------------------------------# -Question: - -Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list. - - -Hints: -Use if/elif to deal with conditions. - - -Solution: - -import math -def bin_search(li, element): - bottom = 0 - top = len(li)-1 - index = -1 - while top>=bottom and index==-1: - mid = int(math.floor((top+bottom)/2.0)) - if li[mid]==element: - index = mid - elif li[mid]>element: - top = mid-1 - else: - bottom = mid+1 - - return index - -li=[2,5,7,9,11,17,222] -print bin_search(li,11) -print bin_search(li,12) - - - - -#----------------------------------------# -Question: - -Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list. - - -Hints: -Use if/elif to deal with conditions. - - -Solution: - -import math -def bin_search(li, element): - bottom = 0 - top = len(li)-1 - index = -1 - while top>=bottom and index==-1: - mid = int(math.floor((top+bottom)/2.0)) - if li[mid]==element: - index = mid - elif li[mid]>element: - top = mid-1 - else: - bottom = mid+1 - - return index - -li=[2,5,7,9,11,17,222] -print bin_search(li,11) -print bin_search(li,12) - - - - -#----------------------------------------# -Question: - -Please generate a random float where the value is between 10 and 100 using Python math module. - - - -Hints: -Use random.random() to generate a random float in [0,1]. - - -Solution: - -import random -print random.random()*100 - -#----------------------------------------# -Question: - -Please generate a random float where the value is between 5 and 95 using Python math module. - - - -Hints: -Use random.random() to generate a random float in [0,1]. - - -Solution: - -import random -print random.random()*100-5 - - -#----------------------------------------# -Question: - -Please write a program to output a random even number between 0 and 10 inclusive using random module and list comprehension. - - - -Hints: -Use random.choice() to a random element from a list. - - -Solution: - -import random -print random.choice([i for i in range(11) if i%2==0]) - - -#----------------------------------------# -Question: - -Please write a program to output a random number, which is divisible by 5 and 7, between 0 and 10 inclusive using random module and list comprehension. - - - -Hints: -Use random.choice() to a random element from a list. - - -Solution: - -import random -print random.choice([i for i in range(201) if i%5==0 and i%7==0]) - - - -#----------------------------------------# - -Question: - -Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive. - - - -Hints: -Use random.sample() to generate a list of random values. - - -Solution: - -import random -print random.sample(range(100), 5) - -#----------------------------------------# -Question: - -Please write a program to randomly generate a list with 5 even numbers between 100 and 200 inclusive. - - - -Hints: -Use random.sample() to generate a list of random values. - - -Solution: - -import random -print random.sample([i for i in range(100,201) if i%2==0], 5) - - -#----------------------------------------# -Question: - -Please write a program to randomly generate a list with 5 numbers, which are divisible by 5 and 7 , between 1 and 1000 inclusive. - - - -Hints: -Use random.sample() to generate a list of random values. - - -Solution: - -import random -print random.sample([i for i in range(1,1001) if i%5==0 and i%7==0], 5) - -#----------------------------------------# - -Question: - -Please write a program to randomly print a integer number between 7 and 15 inclusive. - - - -Hints: -Use random.randrange() to a random integer in a given range. - - -Solution: - -import random -print random.randrange(7,16) - -#----------------------------------------# - -Question: - -Please write a program to compress and decompress the string "hello world!hello world!hello world!hello world!". - - - -Hints: -Use zlib.compress() and zlib.decompress() to compress and decompress a string. - - -Solution: - -import zlib -s = 'hello world!hello world!hello world!hello world!' -t = zlib.compress(s) -print t -print zlib.decompress(t) - -#----------------------------------------# -Question: - -Please write a program to print the running time of execution of "1+1" for 100 times. - - - -Hints: -Use timeit() function to measure the running time. - -Solution: - -from timeit import Timer -t = Timer("for i in range(100):1+1") -print t.timeit() - -#----------------------------------------# -Question: - -Please write a program to shuffle and print the list [3,6,7,8]. - - - -Hints: -Use shuffle() function to shuffle a list. - -Solution: - -from random import shuffle -li = [3,6,7,8] -shuffle(li) -print li - -#----------------------------------------# -Question: - -Please write a program to shuffle and print the list [3,6,7,8]. - - - -Hints: -Use shuffle() function to shuffle a list. - -Solution: - -from random import shuffle -li = [3,6,7,8] -shuffle(li) -print li - - - -#----------------------------------------# -Question: - -Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"]. - -Hints: -Use list[index] notation to get a element from a list. - -Solution: - -subjects=["I", "You"] -verbs=["Play", "Love"] -objects=["Hockey","Football"] -for i in range(len(subjects)): - for j in range(len(verbs)): - for k in range(len(objects)): - sentence = "%s %s %s." % (subjects[i], verbs[j], objects[k]) - print sentence - - -#----------------------------------------# -Please write a program to print the list after removing delete even numbers in [5,6,77,45,22,12,24]. - -Hints: -Use list comprehension to delete a bunch of element from a list. - -Solution: - -li = [5,6,77,45,22,12,24] -li = [x for x in li if x%2!=0] -print li - -#----------------------------------------# -Question: - -By using list comprehension, please write a program to print the list after removing delete numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155]. - -Hints: -Use list comprehension to delete a bunch of element from a list. - -Solution: - -li = [12,24,35,70,88,120,155] -li = [x for x in li if x%5!=0 and x%7!=0] -print li - - -#----------------------------------------# -Question: - -By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th,6th numbers in [12,24,35,70,88,120,155]. - -Hints: -Use list comprehension to delete a bunch of element from a list. -Use enumerate() to get (index, value) tuple. - -Solution: - -li = [12,24,35,70,88,120,155] -li = [x for (i,x) in enumerate(li) if i%2!=0] -print li - -#----------------------------------------# - -Question: - -By using list comprehension, please write a program generate a 3*5*8 3D array whose each element is 0. - -Hints: -Use list comprehension to make an array. - -Solution: - -array = [[ [0 for col in range(8)] for col in range(5)] for row in range(3)] -print array - -#----------------------------------------# -Question: - -By using list comprehension, please write a program to print the list after removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155]. - -Hints: -Use list comprehension to delete a bunch of element from a list. -Use enumerate() to get (index, value) tuple. - -Solution: - -li = [12,24,35,70,88,120,155] -li = [x for (i,x) in enumerate(li) if i not in (0,4,5)] -print li - - - -#----------------------------------------# - -Question: - -By using list comprehension, please write a program to print the list after removing the value 24 in [12,24,35,24,88,120,155]. - -Hints: -Use list's remove method to delete a value. - -Solution: - -li = [12,24,35,24,88,120,155] -li = [x for x in li if x!=24] -print li - - -#----------------------------------------# -Question: - -With two given lists [1,3,6,78,35,55] and [12,24,35,24,88,120,155], write a program to make a list whose elements are intersection of the above given lists. - -Hints: -Use set() and "&=" to do set intersection operation. - -Solution: - -set1=set([1,3,6,78,35,55]) -set2=set([12,24,35,24,88,120,155]) -set1 &= set2 -li=list(set1) -print li - -#----------------------------------------# - -With a given list [12,24,35,24,88,120,155,88,120,155], write a program to print this list after removing all duplicate values with original order reserved. - -Hints: -Use set() to store a number of values without duplicate. - -Solution: - -def removeDuplicate( li ): - newli=[] - seen = set() - for item in li: - if item not in seen: - seen.add( item ) - newli.append(item) - - return newli - -li=[12,24,35,24,88,120,155,88,120,155] -print removeDuplicate(li) - - -#----------------------------------------# -Question: - -Define a class Person and its two child classes: Male and Female. All classes have a method "getGender" which can print "Male" for Male class and "Female" for Female class. - -Hints: -Use Subclass(Parentclass) to define a child class. - -Solution: - -class Person(object): - def getGender( self ): - return "Unknown" - -class Male( Person ): - def getGender( self ): - return "Male" - -class Female( Person ): - def getGender( self ): - return "Female" - -aMale = Male() -aFemale= Female() -print aMale.getGender() -print aFemale.getGender() - - - -#----------------------------------------# -Question: - -Please write a program which count and print the numbers of each character in a string input by console. - -Example: -If the following string is given as input to the program: - -abcdefgabc - -Then, the output of the program should be: - -a,2 -c,2 -b,2 -e,1 -d,1 -g,1 -f,1 - -Hints: -Use dict to store key/value pairs. -Use dict.get() method to lookup a key with default value. - -Solution: - -dic = {} -s=raw_input() -for s in s: - dic[s] = dic.get(s,0)+1 -print '\n'.join(['%s,%s' % (k, v) for k, v in dic.items()]) - -#----------------------------------------# - -Question: - -Please write a program which accepts a string from console and print it in reverse order. - -Example: -If the following string is given as input to the program: - -rise to vote sir - -Then, the output of the program should be: - -ris etov ot esir - -Hints: -Use list[::-1] to iterate a list in a reverse order. - -Solution: - -s=raw_input() -s = s[::-1] -print s - -#----------------------------------------# - -Question: - -Please write a program which accepts a string from console and print the characters that have even indexes. - -Example: -If the following string is given as input to the program: - -H1e2l3l4o5w6o7r8l9d - -Then, the output of the program should be: - -Helloworld - -Hints: -Use list[::2] to iterate a list by step 2. - -Solution: - -s=raw_input() -s = s[::2] -print s -#----------------------------------------# - - -Question: - -Please write a program which prints all permutations of [1,2,3] - - -Hints: -Use itertools.permutations() to get permutations of list. - -Solution: - -import itertools -print list(itertools.permutations([1,2,3])) - -#----------------------------------------# -Question: - -Write a program to solve a classic ancient Chinese puzzle: -We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have? - -Hint: -Use for loop to iterate all possible solutions. - -Solution: - -def solve(numheads,numlegs): - ns='No solutions!' - for i in range(numheads+1): - j=numheads-i - if 2*i+4*j==numlegs: - return i,j - return ns,ns - -numheads=35 -numlegs=94 -solutions=solve(numheads,numlegs) -print solutions - -#----------------------------------------# - - diff --git a/comic.png b/comic.png deleted file mode 100644 index 2ff864e7..00000000 Binary files a/comic.png and /dev/null differ diff --git a/python contents.txt b/python contents.txt deleted file mode 100644 index db6c7e86..00000000 --- a/python contents.txt +++ /dev/null @@ -1,188 +0,0 @@ -Python -The below table largely covers the TOC for 5 popular books. Learning Python (Fourth Edition) has a more in-depth look at concepts than any of the other books. However this book also does not essentially cover some aspects that are covered in other books. -No. Diving into Python The Python Standard Library by Example Python Essential Reference (4th edition) The Quick Python Book Learning Python -Introductory Concepts covering installation on different OS, version history, interpreter. This section also covers questions like Why, Who, What and Where on Python. -1 1. Installing Python -2. Which Python is right for you ? -3. Python & your OS -4. Interactive Shell -5. Summary 1. Introduction (Text) 1. Tutorial Introduction -2. Lexical Conventions and Syntax 1. About Python -2. Getting Started 1. Python Q & A Session -1. Why do people use Python ? -2. Downside of using it -3. Who uses Python Today ? -4. What Can I do with Python ? -5. Python vs Language X -6. Test your Knowledge -2. How Python runs programs -1. Python Interpreter -2. Program Execution -1. Programmer View -2. Python View -3. Execution Model Variations -1. Implementation Alternatives -2. Execution Optimization Tools -3. Frozen Binaries -3. How you run programs -1. Interactive prompt -2. Your first script - -Python Object Types, Numeric Types, Data Structures, Control Structures, Scopes and Arguments -2 1. Your first program -2. Declaring Functions -3. Python Data types vs Other Languages -4. Documenting Functions -5. Everything is an Object -6. The Import Search Path -7. What is an Object ? -8. Indenting Code -9. Testing Modules -10. Native Datatypes -1. Dictionaries -2. List -3. Tuples -11. Variables & referencing 1. Data Structures 1. Types and Objects -2. Operators and Expressions -3. Program Structure and Control Flow -4. Functions and Functional Programming -5. Classes and Object Oriented Programming -6. Modules, Packages and Distribution -7. Input and Output -8. Execution Environment -9. Testing, Debugging, Profiling and Tuning - -Data Structures, Algorithms & Code simplification -String & Text Handling 1. Python Overview -1. Built-in Data types -2. Control Structures -3. Module -4. OOPs -2. Basics -1. Lists -2. Dictionaries -3. Tuple -4. Sets -5. Strings -6. Control Flow -3. Functions -4. Modules and Scoping Rules -5. Python Programs 1. Introducing Python Object Types -1. Why use built-in Types ? -2. Core data types -3. Numbers, Lists, Dictionaries, Tuples, Files, Other Core Types -4. User Defined Classes -2. Numeric Types -1. Literals, Built-in tools, expression operators -2. Formats, Comparisons, Division, Precision -3. Complex Numbers -4. Hexadecimal, Octal & Binary -5. Bitwise Operations -6. Decimal, Fraction, Sets, Booleans - -1. Statements & Syntax -2. Assignments, Expressions & Syntax -3. If Tests & Syntax Rules -4. Scopes -5. Arguments -Built-in functions, Function Design, Recursive Functions, Introspection, Annotations, Lambda, Filter and Reduce -3 1. Power of Introspection -1. Optional and Named Arguments -2. type, str, dir and other built-in functions -3. Object References with getattr -4. Filtering Lists -5. Lambda Functions -6. Real world Lambda functions - None 1. Built-in functions -2. Python run-time services None Built-in functions are covered as part of the topic above but from a numeric perspective -1. Advanced Function Topics -1. Function Design -2. Recursive Functions -3. Attributes and Annotation -4. Lambda -5. Mapping Functions over sequences -6. Filter and Reduce - -Special Class Attributes -Display Tool -OOPS, Modules -4 1. Objects and Object Orientation -1. Importing Modules -2. Defining Classes -3. Initializing and Coding Classes -4. Self & __init__ -5. Instantiating Classes -6. Garbage Collection -7. Wrapper Classes -8. Special Class Methods -9. Advanced Class Methods -10. Class Attributes -11. Private Functions None Covered partially section 2 1. Packages -2. Data Types and Objects -3. Advanced Object Oriented Features 1. Modules -1. Why use Modules ? -2. Program Architecture -3. Module Search Path -4. Module Creation & Usage -5. Namespaces -6. Reloading Modules -7. Packages -2. Advanced Module Topics -1. Data Hiding in Modules -2. as Extension for import and from -3. Modules are Objects: Metaprograms -4. Transitive Module Reloads -5. Module Design Concepts -6. Module Gotchas -3. OOP -1. Why use classes ? -2. Classes & Instances -3. Attribute Inheritance Search -4. Class Method Calls -5. Class Trees -6. Class Objects & Default Behavior -7. Instance Objects are Concrete Items -8. Intercepting Python Operators -9. Classes Vs. Dictionaries -10. Class customization by Inheritance -11. Operator Overloading -12. Subclasses -13. Polymorphism in Action -14. Designing with Classes -15. Mix-in Classes -Advanced Class Topics -5 None None None None 1. Advanced Class Topics -1. Extending Types by Embedding -2. Extending Types by Subclassing -3. Static and Class Methods -4. Decorators and Metaclasses -5. Class Gotchas -Exceptions -6 1. Exceptions and File Handling -1. Handling Exceptions -2. Using exceptions for other purposes 1. Exceptions 1. Exceptions Basics -1. Why use Exceptions ? -2. Default Exception Handler -3. User-Defined Exceptions -4. Class Based Exceptions -5. Designing with Exceptions -XML, HTTP, SOAP, Network Programming, I18N, Unicode -7 1. Regular Expressions -2. Parsing / Processing Mark-up languages (HTML, XML) -1. Unicode -3. HTTP Web Services -1. Headers -2. Debugging -4. SOAP Web Services 1. Networking -2. Internet -3. Email -4. Internationalization and Localization 1. Network Programming and Sockets -2. Internet Application Programming -3. Web Programming -4. Internet Data Handling & Encoding 1. Network, web programming 1. Unicode and Bytes Strings -Miscellaneous -8 None 1. Algorithms -2. Cryptography -3. Data compression and archiving -4. Processes and Threads -5. Data persistence & exchange 1. Extending & Embedding Python 1. GUI None diff --git a/python_111_questions.ipynb b/python_111_questions.ipynb new file mode 100644 index 00000000..1cd8c046 --- /dev/null +++ b/python_111_questions.ipynb @@ -0,0 +1,4452 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 1\n", + "\n", + "Question:\n", + "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).\n", + "The numbers obtained should be printed in a comma-separated sequence on a single line.\n", + "\n", + "Hints: \n", + "Consider use range(#begin, #end) method" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199," + ] + } + ], + "source": [ + "for i in range(2000,3201):\n", + " if (i % 7==0) and ( i % 5!=0):\n", + " print(i,end=\",\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 2\n", + "\n", + "Question:\n", + "Write a program which can compute the factorial of a given numbers.\n", + "The results should be printed in a comma-separated sequence on a single line.\n", + "Suppose the following input is supplied to the program:\n", + "8\n", + "Then, the output should be:\n", + "40320\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40320\n" + ] + } + ], + "source": [ + "a=int(input(\"enter the number:\"))\n", + "f=1\n", + "for i in range(1,a+1):\n", + " f=f*i\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40320\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 3\n", + "\n", + "Question:\n", + "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.\n", + "Suppose the following input is supplied to the program:\n", + "8\n", + "Then, the output should be:\n", + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "Consider use dict()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n" + ] + } + ], + "source": [ + "a=int(input(\"enter the numer:\"))\n", + "d=dict()\n", + "for i in range(1,a+1):\n", + " d[i]=i*i\n", + "print(d)\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 4\n", + "\n", + "Question:\n", + "Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.\n", + "Suppose the following input is supplied to the program:\n", + "34,67,55,33,12,98\n", + "Then, the output should be:\n", + "['34', '67', '55', '33', '12', '98']\n", + "('34', '67', '55', '33', '12', '98')\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "tuple() method can convert list to tuple" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "34,67,55,33,12\n", + "['34', '67', '55', '33', '12']\n", + "('34', '67', '55', '33', '12')\n" + ] + } + ], + "source": [ + "values = input()\n", + "print(values)\n", + "l = values.split(\",\")\n", + "t = tuple(l)\n", + "print(l)\n", + "print(t)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['34', '67', '55', '33', '12', '98']\n", + "('34', '67', '55', '33', '12', '98')\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 5\n", + "\n", + "Question:\n", + "Define a class which has at least two methods:\n", + "getString: to get a string from console input\n", + "printString: to print the string in upper case.\n", + "Also please include simple test function to test the class methods.\n", + "\n", + "Hints:\n", + "Use __init__ method to construct some parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PYTHON CLASS\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 6\n", + "\n", + "Question:\n", + "Write a program that calculates and prints the value according to the given formula:\n", + "Q = Square root of [(2 * C * D)/H]\n", + "Following are the fixed values of C and H:\n", + "C is 50. H is 30.\n", + "D is the variable whose values should be input to your program in a comma-separated sequence.\n", + "Example\n", + "Let us assume the following comma separated input sequence is given to the program:\n", + "100,150,180\n", + "The output of the program should be:\n", + "18,22,24\n", + "\n", + "Hints:\n", + "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)\n", + "In case of input data being supplied to the question, it should be assumed to be a console input. " + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100,150,180\n", + "18,22,24\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "l=[]\n", + "a= input(\"enter numbers\")\n", + "print(a)\n", + "b=a.split(\",\")\n", + "c,h=50,30\n", + "for d in b:\n", + " q=math.sqrt((2*c*int(d))/h)\n", + " l.append(str(int(q//1)))\n", + "print(','.join(l))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "18,22,24\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 7\n", + "\n", + "Question:\n", + "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.\n", + "Note: i=0,1.., X-1; j=0,1,¡­Y-1.\n", + "Example\n", + "Suppose the following inputs are given to the program:\n", + "3,5\n", + "Then, the output of the program should be:\n", + "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] \n", + "\n", + "Hints:\n", + "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.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "x,y=map(int,input(\"enter two numer with comma\").split(\",\"))\n", + "arr=np.zeros((x,y),dtype=int)\n", + "for i in range(x):\n", + " for j in range(y):\n", + " arr[i][j]=i*j\n", + "arr.tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 8\n", + "\n", + "Question:\n", + "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.\n", + "Suppose the following input is supplied to the program:\n", + "without,hello,bag,world\n", + "Then, the output should be:\n", + "bag,hello,without,world\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bag,hello,without,world\n" + ] + } + ], + "source": [ + "w=input(\"enter comma sep words\").split(\",\")\n", + "b=sorted(w)\n", + "print(\",\".join(b))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bag,hello,without,world\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 9\n", + "\n", + "Question:\n", + "Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.\n", + "Suppose the following input is supplied to the program:\n", + "Hello world\n", + "Practice makes perfect\n", + "Then, the output should be:\n", + "HELLO WORLD\n", + "PRACTICE MAKES PERFECT\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HELLO WORLD\n", + "PRACTICE MAKES PERFECT\n" + ] + } + ], + "source": [ + "a='''Hello world\n", + "Practice makes perfect'''\n", + "print(a.upper())" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HELLO WORLD PRACTICE MAKES PERFECT\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 10\n", + "\n", + "Question:\n", + "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.\n", + "Suppose the following input is supplied to the program:\n", + "hello world and practice makes perfect and hello world again\n", + "Then, the output should be:\n", + "again and hello makes perfect practice world\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "We use set container to remove duplicated data automatically and then use sorted() to sort the data." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "again and hello makes perfect practice world\n" + ] + } + ], + "source": [ + "a=\"hello world and practice makes perfect and hello world again\"\n", + "a=set(a.split(\" \"))\n", + "b=sorted(a)\n", + "print(\" \".join(b))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "again and hello makes perfect practice world\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 11\n", + "\n", + "Question:\n", + "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.\n", + "Example:\n", + "0100,0011,1010,1001\n", + "Then the output should be:\n", + "1010\n", + "Notes: Assume the data is input by console.\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "1010\n" + ] + } + ], + "source": [ + "#a=map(int,input(\"enter the numbers\").split())\n", + "a='1010'\n", + "b=int(a,2)\n", + "print(b)\n", + "value = []\n", + "items = [x for x in input().split(',')]\n", + "for p in items:\n", + " intp = int(p, 2)\n", + " if intp % 5==0:\n", + " value.append(p)\n", + "\n", + "print(','.join(value))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1010\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 12\n", + "\n", + "Question:\n", + "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.\n", + "The numbers obtained should be printed in a comma-separated sequence on a single line.\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2000,2002,2004,2006,2008,2020,2022,2024,2026,2028,2040,2042,2044,2046,2048,2060,2062,2064,2066,2068,2080,2082,2084,2086,2088,2200,2202,2204,2206,2208,2220,2222,2224,2226,2228,2240,2242,2244,2246,2248,2260,2262,2264,2266,2268,2280,2282,2284,2286,2288,2400,2402,2404,2406,2408,2420,2422,2424,2426,2428,2440,2442,2444,2446,2448,2460,2462,2464,2466,2468,2480,2482,2484,2486,2488,2600,2602,2604,2606,2608,2620,2622,2624,2626,2628,2640,2642,2644,2646,2648,2660,2662,2664,2666,2668,2680,2682,2684,2686,2688,2800,2802,2804,2806,2808,2820,2822,2824,2826,2828,2840,2842,2844,2846,2848,2860,2862,2864,2866,2868,2880,2882,2884,2886,2888\n" + ] + } + ], + "source": [ + "n=[]\n", + "for i in range(1000,3001):\n", + " s=str(i)\n", + " if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0) and (int(s[3])%2==0):\n", + " n.append(s)\n", + "print(\",\".join(n))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2000,2002,2004,2006,2008,2020,2022,2024,2026,2028,2040,2042,2044,2046,2048,2060,2062,2064,2066,2068,2080,2082,2084,2086,2088,2200,2202,2204,2206,2208,2220,2222,2224,2226,2228,2240,2242,2244,2246,2248,2260,2262,2264,2266,2268,2280,2282,2284,2286,2288,2400,2402,2404,2406,2408,2420,2422,2424,2426,2428,2440,2442,2444,2446,2448,2460,2462,2464,2466,2468,2480,2482,2484,2486,2488,2600,2602,2604,2606,2608,2620,2622,2624,2626,2628,2640,2642,2644,2646,2648,2660,2662,2664,2666,2668,2680,2682,2684,2686,2688,2800,2802,2804,2806,2808,2820,2822,2824,2826,2828,2840,2842,2844,2846,2848,2860,2862,2864,2866,2868,2880,2882,2884,2886,2888\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 13\n", + "\n", + "Question:\n", + "Write a program that accepts a sentence and calculate the number of letters and digits.\n", + "Suppose the following input is supplied to the program:\n", + "hello world! 123\n", + "Then, the output should be:\n", + "LETTERS 10\n", + "DIGITS 3\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Letters 10\n", + "digits 3\n" + ] + } + ], + "source": [ + "c=input(\"enter the sentence\")\n", + "a,d=0,0\n", + "for i in c:\n", + " if i.isalpha():\n", + " a+=1\n", + " elif i.isdigit():\n", + " d+=1\n", + "print(\"Letters \",a)\n", + "print(\"digits \",d)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "LETTERS 10\n", + "DIGITS 3\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 14\n", + "\n", + "Question:\n", + "Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.\n", + "Suppose the following input is supplied to the program:\n", + "Hello world!\n", + "Then, the output should be:\n", + "UPPER CASE 1\n", + "LOWER CASE 9\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Letters 1\n", + "digits 9\n" + ] + } + ], + "source": [ + "c=input(\"enter the sentence\")\n", + "a,d=0,0\n", + "for i in c:\n", + " if i.isupper():\n", + " a+=1\n", + " elif i.islower():\n", + " d+=1\n", + "print(\"Letters \",a)\n", + "print(\"digits \",d)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "UPPER CASE 1\n", + "LOWER CASE 9\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 15\n", + "\n", + "Question:\n", + "Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a.\n", + "Suppose the following input is supplied to the program:\n", + "9\n", + "Then, the output should be:\n", + "11106\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11106" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s,n=0,input(\"enter num\")\n", + "a=\"a+aa+aaa+aaaa\"\n", + "b=a.replace('a',n).split(\"+\")\n", + "for i in c:\n", + " s=s+int(i)\n", + "s\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11106\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 17\n", + "\n", + "Question:\n", + "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:\n", + "D 100\n", + "W 200\n", + "\n", + "D means deposit while W means withdrawal.\n", + "Suppose the following input is supplied to the program:\n", + "D 300\n", + "D 300\n", + "W 200\n", + "D 100\n", + "Then, the output should be:\n", + "500\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input." + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "500" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "t=input(\"enter trans\").split(\" \")\n", + "s=0\n", + "for i in range(len(t)):\n", + " if t[i]==\"D\":\n", + " s=s+int(t[i+1]) \n", + " elif t[i]==\"W\":\n", + " s=s-int(t[i+1])\n", + "\n", + "s" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "500\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 18\n", + "\n", + "Question:\n", + "A website requires the users to input username and password to register. Write a program to check the validity of password input by users.\n", + "Following are the criteria for checking the password:\n", + "1. At least 1 letter between[a-z]\n", + "2. At least 1 number between[0-9]\n", + "1. At least 1 letter between[A-Z]\n", + "3. At least 1 character from [$ # @]\n", + "4. Minimum length of transaction password: 6\n", + "5. Maximum length of transaction password: 12\n", + "Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma.Example\n", + "If the following passwords are given as input to the program:\n", + "ABd1234@1, a F1 # ,2w3E*,2We3345\n", + "Then, the output of the program should be:\n", + "ABd1234@1\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ABd1234@1\n" + ] + } + ], + "source": [ + "import re\n", + "value = []\n", + "items = [x for x in input().split(',')]\n", + "for p in items:\n", + " if len(p) < 6 or len(p) > 12:\n", + " continue\n", + " if not re.search(\"[a-z]\", p):\n", + " continue\n", + " elif not re.search(\"[0-9]\", p):\n", + " continue\n", + " elif not re.search(\"[A-Z]\", p):\n", + " continue\n", + " elif not re.search(\"[$#@]\", p):\n", + " continue\n", + " elif re.search(\"\\s\", p):\n", + " continue\n", + " \n", + " value.append(p)\n", + "print(\",\".join(value))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ABd1234@1\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 19\n", + "\n", + "Question:\n", + "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:\n", + "1: Sort based on name;\n", + "2: Then sort based on age;\n", + "3: Then sort by score.\n", + "The priority is that name > age > score.\n", + "If the following tuples are given as input to the program:\n", + "Tom,19,80\n", + "John,20,90\n", + "Jony,17,91\n", + "Jony,17,93\n", + "Json,21,85\n", + "Then, the output of the program should be:\n", + "[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')]\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.from operator import itemgetter, attrgetter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('Tom', '19', '80 John', '20', '90 Jony', '17', '91 Jony', '17', '93 Json', '21', '85')]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 20\n", + "\n", + "Question:\n", + "Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.\n", + "\n", + "Hints:\n", + "Consider use yield" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 21\n", + "\n", + "Question\n", + "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:\n", + "UP 5\n", + "DOWN 3\n", + "LEFT 3\n", + "RIGHT 2\n", + "¡­\n", + "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.\n", + "Example:\n", + "If the following tuples are given as input to the program:\n", + "UP 5\n", + "DOWN 3\n", + "LEFT 3\n", + "RIGHT 2\n", + "Then, the output of the program should be:\n", + "2\n", + "\n", + "Hints:\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 22\n", + "\n", + "Question:\n", + "Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. \n", + "Suppose the following input is supplied to the program:\n", + "New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.\n", + "Then, the output should be:\n", + "2:2\n", + "3.:1\n", + "3?:1\n", + "New:1\n", + "Python:5\n", + "Read:1\n", + "and:1\n", + "between:1\n", + "choosing:1\n", + "or:2\n", + "to:1\n", + "\n", + "Hints\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2:2\n", + "3.:1\n", + "3?:1\n", + "New:1\n", + "Python:5\n", + "Read:1\n", + "and:1\n", + "between:1\n", + "choosing:1\n", + "or:2\n", + "to:1\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 23\n", + "\n", + "Question:\n", + "Write a method which can calculate square value of number\n", + "\n", + "Hints:\n", + "Using the ** operator" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "9\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 24\n", + "\n", + "\n", + "Question:\n", + "\n", + "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.\n", + "\n", + "Please write a program to print some Python built-in functions documents, such as abs(), int(), raw_input()\n", + "\n", + "And add document for your own function\n", + "Hints:\n", + "The built-in document method is __doc__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Return the absolute value of the argument.\n", + "int([x]) -> integer\n", + "int(x, base=10) -> integer\n", + "\n", + "Convert a number or string to an integer, or return 0 if no arguments\n", + "are given. If x is a number, return x.__int__(). For floating point\n", + "numbers, this truncates towards zero.\n", + "\n", + "If x is not a number or if base is given, then x must be a string,\n", + "bytes, or bytearray instance representing an integer literal in the\n", + "given base. The literal can be preceded by '+' or '-' and be surrounded\n", + "by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n", + "Base 0 means to interpret the base from the string as an integer literal.\n", + ">>> int('0b100', base=0)\n", + "4\n", + "Forward raw_input to frontends\n", + "\n", + " Raises\n", + " ------\n", + " StdinNotImplementedError if active frontend doesn't support stdin.\n", + " \n", + "4\n", + "Return the square value of the input number.\n", + " \n", + " The input number must be integer.\n", + " \n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 25\n", + "\n", + "Question:\n", + "Define a class, which have a class parameter and have a same instance parameter.\n", + "\n", + "Hints:\n", + "Define a instance parameter, need add it in __init__ method\n", + "You can init a object with construct parameter or set the value later" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Person name is Jeffrey\n", + "Person name is Nico\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 26:\n", + "Define a function which can compute the sum of two numbers.\n", + "\n", + "Hints:\n", + "Define a function with two numbers as arguments. You can compute the sum in the function and return the value.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 27\n", + "Define a function that can convert a string into a float and print it in console.\n", + "\n", + "Hints:\n", + "\n", + "Use float() to convert a number to string.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.3\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 29\n", + "Define a function that can receive two integral numbers in string form and compute their sum and then print it in console.\n", + "\n", + "Hints:\n", + "\n", + "Use int() to convert a string to integer.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 30\n", + "Define a function that can accept two strings as input and concatenate them and then print it in console.\n", + "\n", + "Hints:\n", + "\n", + "Use + to concatenate the strings" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "34\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 31\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use len() function to get the length of a string\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "three\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 32\n", + "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\".\n", + "\n", + "Hints:\n", + "\n", + "Use % operator to check if a number is even or odd." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It is an odd number\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 33\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use dict[key]=value pattern to put entry into a dictionary.\n", + "Use ** operator to get power of a number." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9}\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 34\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use dict[key]=value pattern to put entry into a dictionary.\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225, 16: 256, 17: 289, 18: 324, 19: 361, 20: 400}\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 35\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use dict[key]=value pattern to put entry into a dictionary.\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use keys() to iterate keys in the dictionary. Also we can use item() to get key/value pairs.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "4\n", + "9\n", + "16\n", + "25\n", + "36\n", + "49\n", + "64\n", + "81\n", + "100\n", + "121\n", + "144\n", + "169\n", + "196\n", + "225\n", + "256\n", + "289\n", + "324\n", + "361\n", + "400\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 36\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use dict[key]=value pattern to put entry into a dictionary.\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use keys() to iterate keys in the dictionary. Also we can use item() to get key/value pairs." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n", + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n", + "20\n" + ] + } + ], + "source": [ + "def printDict():\n", + "\td=dict()\n", + "\tfor i in range(1,21):\n", + "\t\td[i]=i**2\n", + "\tfor k in d.keys():\t\n", + "\t\tprint(k)\n", + "\n", + "printDict()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 37\n", + "Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).\n", + "\n", + "Hints:\n", + "\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use list.append() to add values into a list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 38\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use list.append() to add values into a list.\n", + "Use [n1:n2] to slice a list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 39\n", + "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.\n", + "\n", + "Hints:\n", + "\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use list.append() to add values into a list.\n", + "Use [n1:n2] to slice a list\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[256, 289, 324, 361, 400]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 40\n", + "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 all values except the first 5 elements in the list.\n", + "\n", + "Hints:\n", + "\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use list.append() to add values into a list.\n", + "Use [n1:n2] to slice a list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 41\n", + "Define a function which can generate and print a tuple where the value are square of numbers between 1 and 20 (both included). \n", + "\n", + "Hints:\n", + "\n", + "Use ** operator to get power of a number.\n", + "Use range() for loops.\n", + "Use list.append() to add values into a list.\n", + "Use tuple() to get a tuple from a list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400)\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 42\n", + "With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line and the last half values in one line. \n", + "\n", + "Hints:\n", + "\n", + "Use [n1:n2] notation to get a slice from a tuple." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 2, 3, 4, 5)\n", + "(6, 7, 8, 9, 10)\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 43\n", + "Write a program to generate and print another tuple whose values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10). \n", + "\n", + "Hints:\n", + "\n", + "Use \"for\" to iterate the tuple\n", + "Use tuple() to generate a tuple from a list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 4, 6, 8, 10)" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 44\n", + "Write a program which accepts a string as input to print \"Yes\" if the string is \"yes\" or \"YES\" or \"Yes\", otherwise print \"No\". \n", + "\n", + "Hints:\n", + "\n", + "Use if statement to judge condition.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yes\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 45\n", + "Write a program which can filter even numbers in a list by using filter function. The list is: [1,2,3,4,5,6,7,8,9,10].\n", + "\n", + "Hints:\n", + "\n", + "Use filter() to filter some elements in a list.\n", + "Use lambda to define anonymous functions.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 46\n", + "Write a program which can map() to make a list whose elements are square of elements in [1,2,3,4,5,6,7,8,9,10].\n", + "\n", + "Hints\n", + "Use map() to generate a list.\n", + "Use lambda to define anonymous functions." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 47\n", + "Write a program which can map() and filter() to make a list whose elements are square of even number in [1,2,3,4,5,6,7,8,9,10].\n", + "\n", + "Hints\n", + "Use map() to generate a list.\n", + "Use filter() to filter elements of a list.\n", + "Use lambda to define anonymous functions." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 16, 36, 64, 100]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 48\n", + "Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both included).\n", + "\n", + "Hints:\n", + "\n", + "Use filter() to filter elements of a list.\n", + "Use lambda to define anonymous functions." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 49\n", + "Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included).\n", + "\n", + "Hints\n", + "Use map() to generate a list.\n", + "Use lambda to define anonymous functions." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 50\n", + "Define a class named American which has a static method called printNationality.\n", + "\n", + "Hints:\n", + "Use @staticmethod decorator to define class static method." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "America\n", + "America\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 51\n", + "Define a class named American and its subclass NewYorker. \n", + "\n", + "Hints:\n", + "\n", + "Use class Subclass(ParentClass) to define a subclass." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<__main__.American object at 0x0000022F3596C3A0>\n", + "<__main__.NewYorker object at 0x0000022F3596C910>\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 52\n", + "Define a class named Circle which can be constructed by a radius. The Circle class has a method which can compute the area. \n", + "\n", + "Hints:\n", + "\n", + "Use def methodName(self) to define a method.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.56\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 53\n", + "Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a method which can compute the area. \n", + "\n", + "Hints:\n", + "\n", + "Use def methodName(self) to define a method." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 54\n", + "Define a class named Shape and its subclass Square. The Square class has an init function which takes a length as argument. Both classes have a area function which can print the area of the shape where Shape's area is 0 by default.\n", + "\n", + "Hints:\n", + "\n", + "To override a method in super class, we can define a method with the same name in the super class.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 55\n", + "Please raise a RuntimeError exception.\n", + "\n", + "Hints:\n", + "\n", + "Use raise() to raise an exception." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "ename": "RuntimeError", + "evalue": "something wrong", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_14320\\2384397409.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'something wrong'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mRuntimeError\u001b[0m: something wrong" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 56\n", + "Write a function to compute 5/0 and use try/except to catch the exceptions.\n", + "\n", + "Hints:\n", + "\n", + "Use try/except to catch exceptions.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "division by zero!\n", + "In finally block for cleanup\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 57\n", + "Define a custom exception class which takes a string message as attribute.\n", + "\n", + "Hints:\n", + "\n", + "To define a custom exception, we need to define a class inherited from Exception.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 58\n", + "Assuming that we have some email addresses in the \"username@companyname.com\" format, please write program to print the user name of a given email address. Both user names and company names are composed of letters only.\n", + "\n", + "Example:\n", + "If the following email address is given as input to the program:\n", + "\n", + "john@google.com\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "john\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "\n", + "Use \\w to match letters.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "john\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 59\n", + "Assuming that we have some email addresses in the \"username@companyname.com\" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only.\n", + "\n", + "Example:\n", + "If the following email address is given as input to the program:\n", + "\n", + "john@google.com\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "google\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "\n", + "Use \\w to match letters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "google\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 60\n", + "Write a program which accepts a sequence of words separated by whitespace as input to print the words composed of digits only.\n", + "\n", + "Example:\n", + "If the following words is given as input to the program:\n", + "\n", + "2 cats and 3 dogs.\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "['2', '3']\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "\n", + "Use re.findall() to find all substring using regex.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['2', '3']\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 61\n", + "Print a unicode string \"hello world\".\n", + "\n", + "Hints:\n", + "\n", + "Use u'strings' format to define unicode string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world!\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 62\n", + "Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8.\n", + "\n", + "Hints:\n", + "\n", + "Use unicode() function to convert." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 63\n", + "\n", + "Write a program to find prime numbers from given list using lambda function\n", + "num=[1,2,5,7,11,14,19,23,27,29,33,37,47,53,55,60]\n", + "\n", + "Hint: \n", + "use lambda() function " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 5, 7, 11, 19, 23, 29, 37, 47, 53]" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 64\n", + "\n", + "Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0).\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "5\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "3.55\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "Use float() to convert an integer to a float\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.5500000000000003\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 65\n", + "\n", + "Write a program to compute:\n", + "\n", + "f(n) = f(n-1)+100 when n > 0\n", + "and f(0) = 1\n", + "\n", + "with a given n input by console(n > 0).\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "5\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "500\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "We can define recursive function in Python.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "500\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 66\n", + "The Fibonacci Sequence is computed based on the following formula:\n", + "\n", + "f(n) = 0 if n = 0\n", + "f(n) = 1 if n = 1\n", + "f(n) = f(n-1)+f(n-2) if n > 1\n", + "\n", + "Please write a program to compute the value of f(n) with a given n input by console.\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "7\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "13\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n", + "\n", + "Hints:\n", + "We can define recursive function in Python.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "13\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 67\n", + "The Fibonacci Sequence is computed based on the following formula:\n", + "\n", + "f(n) = 0 if n = 0\n", + "f(n) = 1 if n = 1\n", + "f(n) = f(n-1)+f(n-2) if n > 1\n", + "\n", + "Please write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console.\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "7\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "0, 1, 1, 2, 3, 5, 8, 13\n", + "\n", + "\n", + "Hints:\n", + "We can define recursive function in Python.\n", + "Use list comprehension to generate a list from an existing list.\n", + "Use string.join() to join a list of strings.\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,1,1,2,3,5,8,13\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 68\n", + "\n", + "Please write a program using generator to print the even numbers between 0 and n in comma separated form while n is input by console.\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "10\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "0, 2, 4, 6, 8, 10\n", + "\n", + "Hints:\n", + "Use yield to produce the next value in generator.\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,2,4,6,8,10\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 69\n", + "Please write a program using generator to print the numbers which can be divisible by 5 and 7 between 0 and n in comma separated form while n is input by console.\n", + "\n", + "Example:\n", + "If the following n is given as input to the program:\n", + "\n", + "100\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "0, 35, 70\n", + "\n", + "Hints:\n", + "Use yield to produce the next value in generator.\n", + "\n", + "In case of input data being supplied to the question, it should be assumed to be a console input.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,35,70\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 70\n", + "Please write assert statements to verify that every number in the list[2, 4, 6, 8] is even.\n", + "\n", + "Hints:\n", + "Use \"assert expression\" to make assertion.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 number is even\n", + "4 number is even\n", + "6 number is even\n", + "8 number is even\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 71\n", + "Please write a program which accepts basic mathematic expression from console and print the evaluation result.\n", + "\n", + "Example:\n", + "If the following string is given as input to the program:\n", + "\n", + "35+3\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "38\n", + "\n", + "Hints:\n", + "Use eval() to evaluate an expression.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "38\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 72\n", + "Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list.\n", + "\n", + "Hints:\n", + "Use if/elif to deal with conditions.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "-1\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 73\n", + "Please write to Find common elements in two lists\n", + "l1=[10,20,30,40,50,60]\n", + "l2=[15,20,40,55,60,42]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[20, 40, 60]" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 74\n", + "Please generate a random float where the value is between 10 and 100 using Python math module.\n", + "\n", + "Hints:\n", + "Use random.random() to generate a random float in [0, 1].\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "86.73321905515819\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 75\n", + "Please generate a random float where the value is between 5 and 95 using Python math module.\n", + "\n", + "Hints:\n", + "Use random.random() to generate a random float in [0,1]." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "73.72771840488628\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 76\n", + "Please write a program to output a random even number between 0 and 10 inclusive using random module and list comprehension.\n", + "\n", + "Hints:\n", + "Use random.choice() to a random element from a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 77\n", + "Please write a program to output a random number, which is divisible by 5 and 7, between 0 and 10 inclusive using random module and list comprehension.\n", + "\n", + "Hints:\n", + "Use random.choice() to a random element from a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "140\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 78\n", + "Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive.\n", + "\n", + "Hints:\n", + "Use random.sample() to generate a list of random values.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[32, 36, 66, 43, 16]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 79\n", + "Please write a program to randomly generate a list with 5 even numbers between 100 and 200 inclusive.\n", + "\n", + "Hints:\n", + "Use random.sample() to generate a list of random values.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[198, 150, 104, 136, 192]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 80\n", + "Please write a program to randomly generate a list with 5 numbers, which are divisible by 5 and 7, between 1 and 1000 inclusive.\n", + "\n", + "Hints:\n", + "Use random.sample() to generate a list of random values.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 142, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[245, 175, 910, 595, 70]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 81\n", + "Please write a program to randomly print a integer number between 7 and 15 inclusive.\n", + "\n", + "Hints:\n", + "Use random.randrange() to a random integer in a given range.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 82\n", + "Please write a program to compress and decompress the string \"hello world!hello world!hello world!hello world!\".\n", + "\n", + "Hints:\n", + "Use zlib.compress() and zlib.decompress() to compress and decompress a string.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 144, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "b'x\\x9c\\xcbH\\xcd\\xc9\\xc9W(\\xcf/\\xcaIQ\\xcc \\x82\\r\\x00\\xbd[\\x11\\xf5'\n", + "b'hello world!hello world!hello world!hello world!'\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 83\n", + "Please write a program to print the running time of execution of \"1+1\" for 100 times.\n", + "\n", + "Hints:\n", + "Use timeit() function to measure the running time.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 145, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.3674422000003688\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 84\n", + "Please write a program to shuffle and print the list[3, 6, 7, 8].\n", + "\n", + "Hints:\n", + "Use shuffle() function to shuffle a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 146, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7, 3, 8, 6]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 85\n", + "Please write a program to shuffle and print the list[3, 6, 7, 8].\n", + "\n", + "Hints:\n", + "Use shuffle() function to shuffle a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 147, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7, 8, 6, 3]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 86\n", + "Please write a program to generate all sentences where subject is in [\"I\", \"You\"] and verb is in [\"Play\", \"Love\"] and the object is in [\"Hockey\", \"Football\"].\n", + "\n", + "Hints:\n", + "Use list[index] notation to get a element from a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 148, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I Play Hockey.\n", + "I Play Football.\n", + "I Love Hockey.\n", + "I Love Football.\n", + "You Play Hockey.\n", + "You Play Football.\n", + "You Love Hockey.\n", + "You Love Football.\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 87\n", + "Please write a program to print the list after removing delete even numbers in [5, 6, 77, 45, 22, 12, 24].\n", + "\n", + "Hints:\n", + "Use list comprehension to delete a bunch of element from a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 149, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5, 77, 45]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 88\n", + "By using list comprehension, please write a program to print the list after removing delete numbers which are divisible by 5 and 7 in [12, 24, 35, 70, 88, 120, 155].\n", + "\n", + "Hints:\n", + "Use list comprehension to delete a bunch of element from a list.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 150, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[12, 24, 88]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 89\n", + "By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th, 6th numbers in [12, 24, 35, 70, 88, 120, 155].\n", + "\n", + "Hints:\n", + "Use list comprehension to delete a bunch of element from a list.\n", + "Use enumerate() to get(index, value) tuple.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[24, 70, 120]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 90\n", + "By using list comprehension, please write a program generate a 3*5*8 3D array whose each element is 0.\n", + "\n", + "Hints:\n", + "Use list comprehension to make an array.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 91\n", + "By using list comprehension, please write a program to print the list after removing the 0th, 4th, 5th numbers in [12, 24, 35, 70, 88, 120, 155].\n", + "\n", + "Hints:\n", + "Use list comprehension to delete a bunch of element from a list.\n", + "Use enumerate() to get(index, value) tuple.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[24, 35, 70, 155]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 92\n", + "By using list comprehension, please write a program to print the list after removing the value 24 in [12, 24, 35, 24, 88, 120, 155].\n", + "\n", + "Hints:\n", + "Use list's remove method to delete a value.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 154, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[12, 35, 88, 120, 155]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 93\n", + "With two given lists[1, 3, 6, 78, 35, 55] and [12, 24, 35, 24, 88, 120, 155], write a program to make a list whose elements are intersection of the above given lists.\n", + "\n", + "Hints:\n", + "Use set() and \"&=\" to do set intersection operation.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[35]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 94\n", + "With a given list[12, 24, 35, 24, 88, 120, 155, 88, 120, 155], write a program to print this list after removing all duplicate values with original order reserved.\n", + "\n", + "Hints:\n", + "Use set() to store a number of values without duplicate.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[12, 24, 35, 88, 120, 155]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 95\n", + "Define a class Person and its two child classes: Male and Female. All classes have a method \"getGender\" which can print \"Male\" for Male class and \"Female\" for Female class.\n", + "\n", + "Hints:\n", + "Use Subclass(Parentclass) to define a child class.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 157, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Male\n", + "Female\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 96\n", + "Please write a program which count and print the numbers of each character in a string input by console.\n", + "\n", + "Example:\n", + "If the following string is given as input to the program:\n", + "\n", + "abcdefgabc\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "a, 2\n", + "c, 2\n", + "b, 2\n", + "e, 1\n", + "d, 1\n", + "g, 1\n", + "f, 1\n", + "\n", + "Hints:\n", + "Use dict to store key/value pairs.\n", + "Use dict.get() method to lookup a key with default value.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a,2\n", + "b,2\n", + "c,2\n", + "d,1\n", + "e,1\n", + "f,1\n", + "g,1\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 97\n", + "Please write a program which accepts a string from console and print it in reverse order.\n", + "\n", + "Example:\n", + "If the following string is given as input to the program:\n", + "\n", + "rise to vote sir\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "ris etov ot esir\n", + "\n", + "Hints:\n", + "Use list[::-1] to iterate a list in a reverse order.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 161, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ris etov ot esir\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 98\n", + "Please write a program which accepts a string from console and print the characters that have even indexes.\n", + "\n", + "Example:\n", + "If the following string is given as input to the program:\n", + "\n", + "H1e2l3l4o5w6o7r8l9d\n", + "\n", + "Then, the output of the program should be:\n", + "\n", + "Helloworld\n", + "\n", + "Hints:\n", + "Use list[::2] to iterate a list by step 2.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 162, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Helloworld\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 99\n", + "Please write a program which prints all permutations of [1,2,3]\n", + "\n", + "Hints:\n", + "Use itertools.permutations() to get permutations of list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 163, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 100\n", + "Write a program to solve a classic ancient Chinese puzzle:\n", + "We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have?\n", + "\n", + "Hint:\n", + "Use for loop to iterate all possible solutions.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(23, 12)\n" + ] + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 101\n", + "write a Python program that calculates the mean of numbers in a list?\n", + "Calculating the Average of Numbers in Python:take numbers from user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 168, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of Elements to take average of: 4\n", + "Enter the element: 5\n", + "Enter the element: 25\n", + "Enter the element: 74\n", + "Enter the element: 24\n", + "Average of the elements in list 32.0\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 102\n", + "Python program to reverse number:123456" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 169, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "654321\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Question 103\n", + "Count the Number of matching characters in a pair of string\n", + "str1 = 'abcdef'\n", + "str2 = 'defghia'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 170, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " matching characters :- a, d, e, f\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 104\n", + "Program to print double sided stair-case pattern" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 171, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * * \n", + " * * \n", + " * * * * \n", + " * * * * \n", + " * * * * * * \n", + " * * * * * * \n", + " * * * * * * * * \n", + " * * * * * * * * \n", + " * * * * * * * * * * \n", + " * * * * * * * * * * \n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 105\n", + "Program to print the pattern ‘G’" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 172, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " *** \n", + " * \n", + " * \n", + " * *** \n", + " * * \n", + " * * \n", + " *** \n", + "\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 106\n", + "Python – Extract digits from Tuple list\n", + "Input: test_list = [(15, 3), (3, 9)]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The original list is : [(15, 3), (3, 9), (1, 10), (99, 2)]\n", + "The extracted digits : {'1', '9', '5', '2', '0', '3'}\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 107\n", + "Convert Nested Tuple to Custom Key Dictionary\n", + "test_tuple = ((1, ‘Gfg’, 2), (3, ‘best’, 4)), keys = [‘key’, ‘value’, ‘id’]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 174, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The original tuple : ((4, 'Gfg', 10), (3, 'is', 8), (6, 'Best', 10))\n", + "The converted dictionary : [{'key': 4, 'value': 'Gfg', 'id': 10}, {'key': 3, 'value': 'is', 'id': 8}, {'key': 6, 'value': 'Best', 'id': 10}]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 108\n", + "Remove empty tuples from a list\n", + "tuples = [(), (‘ram’,’15’,’8′), (), (‘laxman’, ‘sita’), (‘krishna’, ‘akbar’, ’45’), (”,”),()]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('ram', '15', '8'), ('laxman', 'sita'), ('krishna', 'akbar', '45'), ('', '')]\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 109\n", + "Program to check Armstrong Number\n", + "abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... \n", + "Input: 153\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 177, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 110\n", + "String slicing in Python to check if a string can become empty by recursive deletion\n", + "str = \"Learnbay\", sub_str = \"bay\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 178, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ### Question 111\n", + "Python Dictionary to find mirror characters in a string\n", + "Given a string and a number N, we need to mirror the characters from the N-th position up to the length of the string in alphabetical order. In mirror operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, and so on.\n", + "\n", + "N = 3\n", + "paradox" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 179, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "paizwlc\n" + ] + } + ], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}