├── Day 1 ├── 1.py ├── 2.py ├── 3.py ├── 4.py └── 5.py ├── Day 2 ├── 10.py ├── 6.py ├── 7.py ├── 8.py └── 9.py ├── Day 3 ├── 11.py ├── 12.py ├── 13.py ├── 14.py └── 15.py ├── Day 4 ├── 16.py ├── 17.py ├── 18.py ├── 19.py └── 20.py ├── Day 5 ├── 21.py ├── 22.py ├── 23.py ├── 24.py └── 25.py ├── Day 6 ├── 26.py ├── 27.py ├── 28.py ├── 29.py └── 30.py ├── Day 7 ├── 31.py ├── 32.py ├── 33.py ├── 34.py └── 35.py └── README.md /Day 1/1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 13:52:24 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | # Question 1 9 | > **_Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, 10 | > between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line._** 11 | ''' 12 | li=[] 13 | for i in range(2000, 3201): 14 | if (i%7==0) and (i%5!=0): 15 | li.append(str(i)) 16 | 17 | print (','.join(li)) 18 | 19 | print("\n") 20 | 21 | for i in range(2000,3201): 22 | if i%7 == 0 and i%5!=0: 23 | print(i,end=',') 24 | 25 | print("\n") 26 | 27 | 28 | print(*(i for i in range(2000, 3201) if i%7 == 0 and i%5 != 0), sep=",") 29 | 30 | print("\n") 31 | 32 | 33 | print(list(i for i in range(2000, 3201) if i%7 == 0 and i%5 != 0), sep=",") 34 | -------------------------------------------------------------------------------- /Day 1/2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 14:04:07 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | # Question 2 9 | > **_Write a program which can compute the factorial of a given numbers. 10 | The results should be printed in a comma-separated sequence on a single line. 11 | Suppose the following input is supplied to the program: 8 12 | > Then, the output should be:40320_** 13 | ''' 14 | n = 8 15 | fact = 1 16 | i = 1 17 | while i <= n: 18 | fact = fact * i; 19 | i = i + 1 20 | print(fact) 21 | 22 | 23 | def shortFact(x): return 1 if x <= 1 else x*shortFact(x-1) 24 | print(shortFact(n)) 25 | 26 | 27 | from functools import reduce 28 | 29 | def fun(acc, item): 30 | return acc*item 31 | 32 | print(reduce(fun,range(1, n+1), 1)) 33 | -------------------------------------------------------------------------------- /Day 1/3.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 14:08:49 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | # Question 3 9 | > **_With a given integral number n, write a program to generate a dictionary that contains 10 | (i, i x i) such that is an integral number between 1 and n (both included). 11 | and then the program should print the dictionary.Suppose the following input is 12 | 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}_** 13 | ''' 14 | 15 | n = 8 16 | ans = {} 17 | for i in range (1,n+1): 18 | ans[i] = i * i 19 | print(ans) 20 | 21 | 22 | print({i : i*i for i in range(1,n+1)}) 23 | 24 | 25 | print(dict(enumerate((i * i for i in range(1,n+1)),1))) 26 | -------------------------------------------------------------------------------- /Day 1/4.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 14:15:47 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 4 9 | Write a program which accepts a sequence of comma-separated numbers from console and 10 | generate a list and a tuple which contains every number. 11 | Suppose the following input is supplied to the program: 34,67,55,33,12,98 12 | Then, the output should be: 13 | ['34', '67', '55', '33', '12', '98'] 14 | ('34', '67', '55', '33', '12', '98') 15 | 16 | ''' 17 | numbers = input("Enter comma separated numbers: ") 18 | li = [] 19 | num = '' 20 | for i in numbers: 21 | if i == ',': 22 | if num != '': 23 | li.append(num) 24 | num = '' 25 | continue 26 | elif i != ',' and i != ' ': 27 | num += i 28 | if num != '': 29 | li.append(num) 30 | 31 | print(li) 32 | print(tuple(li)) 33 | 34 | 35 | li2 = numbers.split(sep = ',') 36 | print(li2) 37 | print(tuple(li2)) 38 | -------------------------------------------------------------------------------- /Day 1/5.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 14:54:30 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 5 9 | Define a class which has at least two methods: 10 | getString: to get a string from console input 11 | printString: to print the string in upper case. 12 | Also please include simple test function to test the class methods. 13 | ''' 14 | class MyClass(): 15 | 16 | def getString(self): 17 | self.string = input("Enter a string: ") 18 | 19 | def printString(self): 20 | print(self.string.upper()) 21 | 22 | my_obj = MyClass() 23 | my_obj.getString() 24 | my_obj.printString() 25 | -------------------------------------------------------------------------------- /Day 2/10.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Aug 22 09:34:23 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 10 9 | Write a program that accepts a sequence of whitespace separated words as input 10 | and prints the words after removing all duplicate words and sorting them alphanumerically. 11 | Suppose the following input is supplied to the program: 12 | hello world and practice makes perfect and hello world again 13 | Then, the output should be: 14 | again and hello makes perfect practice world 15 | ''' 16 | message = input(" Enter message: ").split() 17 | print(' '.join(sorted(set(message)))) 18 | 19 | 20 | for i in message: 21 | if message.count(i) > 1: 22 | message.remove(i) 23 | 24 | message.sort() 25 | print(" ".join(message)) 26 | -------------------------------------------------------------------------------- /Day 2/6.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 15:04:05 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 6 9 | Write a program that calculates and prints the value according to the given formula: 10 | Q = Square root of [(2 * C * D)/H] 11 | Following are the fixed values of C and H: 12 | C is 50. H is 30. 13 | D is the variable whose values should be input to your program in a comma-separated sequence. 14 | For example Let us assume the following comma separated input sequence is given to the program:100,150,180 15 | The output of the program should be: 18,22,24 16 | ''' 17 | 18 | num = input("Enter comma separated numbers: ").split(sep = ',') 19 | c = 50 20 | h = 30 21 | li = [] 22 | for d in num: 23 | q = ((2*c*int(d))/h) ** (0.5) 24 | li.append(str(round(q))) 25 | print(','.join(li)) 26 | 27 | 28 | print(','.join(list(map(lambda d:str(round(((2*c*int(d))/h)**(0.5))), num)))) 29 | #print(','.join(list(map(lambda d:str(round(((2*c*int(d))/h)**(0.5))), input().split(sep=','))))) 30 | 31 | 32 | print(*(round((2*c*int(d)/h)**0.5) for d in num), sep=",") 33 | 34 | -------------------------------------------------------------------------------- /Day 2/7.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 15:54:46 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 7 9 | _Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. 10 | The element value in the i-th row and j-th column of the array should be i _ j.* 11 | Note: i=0,1.., X-1; j=0,1,¡­Y-1. Suppose the following inputs are given to the program: 3,5 12 | Then, the output of the program should be: 13 | [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] 14 | ''' 15 | i,j = input("Enter two no.s, comma separated: ").split(sep=',') 16 | i = int(i) 17 | j = int(j) 18 | li=[] 19 | 20 | for row in range(i): 21 | temp_li = [] 22 | for col in range(j): 23 | temp_li.append(col*row) 24 | li.append(temp_li) 25 | print(li) 26 | 27 | 28 | x,y = map(int,input().split(',')) 29 | lst = [[i*j for j in range(y)] for i in range(x)] 30 | print(lst) 31 | -------------------------------------------------------------------------------- /Day 2/8.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 16:19:03 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 8 9 | Write a program that accepts a comma separated sequence of words as input and prints the words in a 10 | comma-separated sequence after sorting them alphabetically. 11 | Suppose the following input is supplied to the program: 12 | without,hello,bag,world 13 | Then, the output should be: 14 | bag,hello,without,world 15 | 16 | ''' 17 | li = input().split(',') 18 | li.sort() 19 | print(*(li),sep=',') 20 | 21 | 22 | print(','.join(li)) 23 | -------------------------------------------------------------------------------- /Day 2/9.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 21 16:27:52 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 9 9 | Write a program that accepts sequence of lines as input and prints the lines after 10 | making all characters in the sentence capitalized. 11 | Suppose the following input is supplied to the program: 12 | Hello world 13 | Practice makes perfect 14 | Then, the output should be: 15 | HELLO WORLD 16 | PRACTICE MAKES PERFECT 17 | ''' 18 | 19 | string = input("Enter paragraph: ") + "\n" 20 | while True: 21 | new_string = input() 22 | string += new_string + "\n" 23 | if new_string == '': 24 | break 25 | 26 | print(string.upper()) 27 | 28 | ############################################# 29 | 30 | def user_input(): 31 | while True: 32 | s = input() 33 | if not s: 34 | return 35 | yield s 36 | 37 | my_list = [] 38 | for line in map(str.upper, user_input()): 39 | my_list.append(line) 40 | 41 | for line in my_list: 42 | print(line) 43 | -------------------------------------------------------------------------------- /Day 3/11.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Aug 22 09:43:00 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 11 9 | Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input 10 | and then check whether they are divisible by 5 or not. 11 | The numbers that are divisible by 5 are to be printed in a comma separated sequence. 12 | Example: 13 | 0100,0011,1010,1001 14 | Then the output should be: 15 | 1010 16 | ''' 17 | data = input("Enter four digit binary no.s: ").split(',') 18 | output_li = [] 19 | 20 | for item in data: 21 | if int(item,2) % 5 == 0: 22 | output_li.append(item) 23 | 24 | print(','.join(output_li)) 25 | 26 | 27 | data = [num for num in data if int(num, 2) % 5 == 0] 28 | print(','.join(data)) 29 | 30 | 31 | data = list(filter(lambda i:int(i,2)%5==0, data)) 32 | print(",".join(data)) 33 | -------------------------------------------------------------------------------- /Day 3/12.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Aug 22 10:05:43 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 12 9 | Write a program, which will find all such numbers between 1000 and 3000 (both included) 10 | such that each digit of the number is an even number.The numbers obtained should be printed 11 | in a comma-separated sequence on a single line. 12 | ''' 13 | num_li = list(range(1000,3001)) 14 | out_li = [] 15 | 16 | for num in num_li: 17 | check = 0 18 | for individual_num in str(num): 19 | if int(individual_num) % 2 == 0: 20 | check += 1 21 | if check == len(str(num)): 22 | out_li.append(str(num)) 23 | 24 | print(','.join(out_li)) 25 | 26 | 27 | def check(element): 28 | return all(int(i) % 2 == 0 for i in element) # all returns True if all digits i is even in element 29 | 30 | lst = [str(i) for i in range(1000,3001)] 31 | lst = list(filter(check,lst)) 32 | print(",".join(lst)) -------------------------------------------------------------------------------- /Day 3/13.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Aug 22 10:06:54 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 13 9 | Write a program that accepts a sentence and calculate the number of letters and digits. 10 | Suppose the following input is supplied to the program: 11 | hello world! 123 12 | Then, the output should be: 13 | LETTERS 10 14 | DIGITS 3 15 | ''' 16 | message = "hello world! 123" 17 | 18 | num = '0123456789' 19 | alphabet = 'abcdefghijklmnopqrstuvwxyz' 20 | alphabet = alphabet + alphabet.upper() 21 | 22 | count_num = 0 23 | count_alpha = 0 24 | 25 | for item in message: 26 | for number in num: 27 | if number == item: 28 | count_num += 1 29 | break 30 | 31 | for letter in alphabet: 32 | if letter == item: 33 | count_alpha += 1 34 | break 35 | 36 | print(f"Letters: {count_alpha}") 37 | print(f"Digits: {count_num}") 38 | 39 | ####################################################### 40 | 41 | word = "hello world! 123" 42 | letter,digit = 0,0 43 | 44 | for i in word: 45 | if ('a'<=i and i<='z') or ('A'<=i and i<='Z'): 46 | letter+=1 47 | if '0'<=i and i<='9': 48 | digit+=1 49 | 50 | print("LETTERS {0}\nDIGITS {1}".format(letter,digit)) 51 | 52 | ######################################################## 53 | 54 | letter, digit = 0,0 55 | 56 | for i in word: 57 | if i.isalpha(): # returns True if alphabet 58 | letter += 1 59 | elif i.isnumeric(): # returns True if numeric 60 | digit += 1 61 | print(f"LETTERS {letter}\nDIGITS {digit}") 62 | 63 | ######################################################## 64 | 65 | import re 66 | counter = {"LETTERS":len(re.findall("[a-zA-Z]", word)), "NUMBERS":len(re.findall("[0-9]", word))} 67 | print(counter) 68 | 69 | -------------------------------------------------------------------------------- /Day 3/14.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 10:42:15 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 14 9 | Write a program that accepts a sentence 10 | and calculate the number of upper case letters and lower case letters. 11 | Suppose the following input is supplied to the program: 12 | Hello world! 13 | Then, the output should be: 14 | UPPER CASE 1 15 | LOWER CASE 9 16 | ''' 17 | data = 'Hello World! How are you?' 18 | count_lower = 0 19 | count_upper = 0 20 | 21 | for letter in data: 22 | if 'a' <= letter <='z': 23 | count_lower += 1 24 | elif 'A' <= letter <='Z': 25 | count_upper += 1 26 | 27 | print(f'UPPER CASE {count_upper}') 28 | print(f'LOWER CASE {count_lower}') 29 | 30 | ############################################## 31 | 32 | upper = sum(1 for i in data if i.isupper()) # sum function cumulatively sum up 1's if the condition is True 33 | lower = sum(1 for i in data if i.islower()) 34 | 35 | print("UPPER CASE {0}\nLOWER CASE {1}".format(upper,lower)) 36 | -------------------------------------------------------------------------------- /Day 3/15.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 11:01:08 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 15 9 | Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a. 10 | Suppose the following input is supplied to the program:9 11 | Then, the output should be:11106 12 | ''' 13 | input = 9 14 | answer = input + (input*10+input) + (input*100+input*10+input) + (input*1000+input*100+input*10+input) 15 | print(answer) 16 | 17 | ######################### 18 | 19 | a = '9' 20 | total,tmp = 0,str() # initialing an integer and empty string 21 | 22 | for i in range(4): 23 | tmp+=a # concatenating 'a' to 'tmp' 24 | total+=int(tmp) # converting string type to integer type 25 | 26 | print(total) 27 | 28 | ######################### 29 | 30 | from functools import reduce 31 | print(reduce(lambda acc, a: int(acc) + int(a), [a*i for i in range(1,5)])) 32 | 33 | ######################### 34 | 35 | total = int(a) + int(2*a) + int(3*a) + int(4*a) 36 | print(total) 37 | -------------------------------------------------------------------------------- /Day 4/16.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 11:14:22 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 16 9 | Use a list comprehension to square each odd number in a list. 10 | The list is input by a sequence of comma-separated numbers. 11 | Suppose the following input is supplied to the program: 1,2,3,4,5,6,7,8,9 12 | Then, the output should be: 1,9,25,49,81 13 | ''' 14 | li = [1,2,3,4,5,6,7,8,9] 15 | ans_li = [i*i for i in li if i % 2 == 1] 16 | print(ans_li) 17 | -------------------------------------------------------------------------------- /Day 4/17.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 11:14:32 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 17 9 | Write a program that computes the net amount of a bank account based a transaction log from console input. 10 | The transaction log format is shown as following: 11 | D 100 12 | W 200 13 | D means deposit while W means withdrawal. 14 | Suppose the following input is supplied to the program: 15 | D 300 16 | D 300 17 | W 200 18 | D 100 19 | Then, the output should be: 20 | 500 21 | ''' 22 | total_D = 0 23 | total_W = 0 24 | data = input("Enter the transaction: ") 25 | 26 | while True: 27 | if not data: 28 | break 29 | else: 30 | if data[0] == 'D': 31 | total_D += int(data[2:]) 32 | elif data[0] == 'W': 33 | total_W += int(data[2:]) 34 | data = input() 35 | 36 | print(total_D-total_W) 37 | 38 | ########################################### 39 | 40 | # total = 0 41 | # while True: 42 | # s = input().split() 43 | # if not s: # break if the string is empty 44 | # break 45 | # cm,num = map(str,s) # two inputs are distributed in cm and num in string data type 46 | 47 | # if cm=='D': 48 | # total+=int(num) 49 | # if cm=='W': 50 | # total-=int(num) 51 | 52 | # print(total) 53 | 54 | ########################################### 55 | 56 | # lst = [] 57 | # while True: 58 | # x = input() 59 | # if len(x)==0: 60 | # break 61 | # lst.append(x) 62 | 63 | # balance = 0 64 | # for item in lst: 65 | # if 'D' in item: 66 | # balance += int(item.strip('D ')) 67 | # if 'W' in item: 68 | # balance -= int(item.strip('W ')) 69 | # print(balance) 70 | 71 | ########################################### 72 | 73 | # transactions = [] 74 | 75 | # while True: 76 | # text = input("> ") 77 | # if text: 78 | # text = text.strip('D ') 79 | # text = text.replace('W ', '-') 80 | # transactions.append(text) 81 | # else: 82 | # break 83 | # 84 | # transactions = (int(i) for i in transactions) 85 | # balance = sum(transactions) 86 | # print(f"Balance is {balance}") 87 | -------------------------------------------------------------------------------- /Day 4/18.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 11:37:51 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 18 9 | A website requires the users to input username and password to register. 10 | Write a program to check the validity of password input by users. 11 | Following are the criteria for checking the password: 12 | At least 1 letter between [a-z] 13 | At least 1 number between [0-9] 14 | At least 1 letter between [A-Z] 15 | At least 1 character from [$#@] 16 | Minimum length of transaction password: 6 17 | Maximum length of transaction password: 12 18 | Your program should accept a sequence of comma separated passwords and will check them 19 | according to the above criteria. Passwords that match the criteria are to be printed, 20 | each separated by a comma. 21 | Example 22 | If the following passwords are given as input to the program: ABd1234@1,a F1#,2w3E*,2We3345 23 | Then, the output of the program should be: ABd1234@1 24 | ''' 25 | def lower_case(password): 26 | for i in password: 27 | if 'a' <= i <= 'z': 28 | return True 29 | return False 30 | 31 | def number(password): 32 | for i in password: 33 | if i in '0123456789': 34 | return True 35 | return False 36 | 37 | def upper_case(password): 38 | for i in password: 39 | if 'A' <= i <= 'Z': 40 | return True 41 | return False 42 | 43 | def special_char(password): 44 | for i in password: 45 | if i in ['$','#','@']: 46 | return True 47 | return False 48 | 49 | def length(password): 50 | if 6 <= len(password) <=12: 51 | return True 52 | return False 53 | 54 | password = 'ABd1234@1,a F1#,2w3E*,2We3345,sauRabh90@' 55 | li_password = password.split(',') 56 | 57 | for pw in li_password: 58 | if lower_case(pw) and number(pw) and upper_case(pw) and special_char(pw) and length(pw): 59 | print(pw, end = ',') 60 | -------------------------------------------------------------------------------- /Day 4/19.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Aug 23 12:01:26 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 19 9 | You are required to write a program to sort the (name, age, score) tuples by ascending order 10 | where name is string, age and score are numbers. The tuples are input by console. The sort criteria is: 11 | 1: Sort based on name 12 | 2: Then sort based on age 13 | 3: Then sort by score 14 | The priority is that name > age > score. 15 | If the following tuples are given as input to the program: 16 | Tom,19,80 17 | John,20,90 18 | Jony,17,91 19 | Jony,17,93 20 | Json,21,85 21 | Then, the output of the program should be: 22 | [('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')] 23 | ''' 24 | data = input("Enter name,age,score: ") 25 | li_data = [] 26 | my_list = [] 27 | 28 | while True: 29 | if not data: 30 | break 31 | li_data.append(data) 32 | data = input() 33 | 34 | for item in li_data: 35 | my_tuple = () 36 | individual_data = item.split(',') 37 | name = individual_data[0] 38 | age = individual_data[1] 39 | score = individual_data[2] 40 | my_tuple = (name,age,score) 41 | my_list.append(my_tuple) 42 | 43 | print(sorted(my_list)) 44 | 45 | ################################### 46 | 47 | lst = [] 48 | while True: 49 | s = input().split(',') 50 | if not s[0]: 51 | break 52 | lst.append(tuple(s)) 53 | 54 | lst.sort(key= lambda x:(x[0],int(x[1]),int(x[2]))) 55 | # here key is defined by lambda and the data is sorted by element priority 0>1>2 in accending order 56 | 57 | print(lst) 58 | 59 | ''' 60 | above is similar to the below example. 61 | 62 | a = [(0,2),(4,4),(10,-1),(5,3)] 63 | a.sort(key=lambda x:x[1], reverse=False) 64 | print(a) 65 | ''' -------------------------------------------------------------------------------- /Day 4/20.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 10:55:46 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 20 9 | Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n. 10 | ''' 11 | class GenClass(): 12 | def __init__(self, num1, num2): 13 | self.num1 = num1 14 | self.num2 = num2 15 | def gen_method(self): 16 | for i in range(self.num1, self.num2 + 1): 17 | if i % 7 == 0: 18 | yield i 19 | 20 | range_num = GenClass(0,100) 21 | for item in range_num.gen_method(): 22 | print(item) 23 | 24 | ############################################ 25 | 26 | class MyGen(): 27 | def by_seven(self, n): 28 | for i in range(0, int(n/7) + 1): 29 | yield i * 7 30 | 31 | for i in MyGen().by_seven(100): 32 | print(i) 33 | 34 | -------------------------------------------------------------------------------- /Day 5/21.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 11:23:20 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 21 9 | A robot moves in a plane starting from the original point (0,0). 10 | The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. 11 | The trace of robot movement is shown as the following: 12 | UP 5 13 | DOWN 3 14 | LEFT 3 15 | RIGHT 2 16 | The numbers after the direction are steps. Please write a program to 17 | compute the distance from current position after a sequence of movement 18 | and original point. If the distance is a float, then just print the 19 | nearest integer. Example: If the following tuples are given as input to the program: 20 | UP 5 21 | DOWN 3 22 | LEFT 3 23 | RIGHT 2 24 | Then, the output of the program should be: 2 25 | ''' 26 | import math 27 | direction = (5,3,3,2) # up, down, left, right 28 | initial_pos = (0,0) 29 | final_pos = (direction[0] - direction[1], - direction[2] + direction[3]) 30 | distance = math.sqrt(((final_pos[0] - initial_pos[0]) ** 2) + ((final_pos[1] - initial_pos[1]) ** 2)) 31 | print(distance) 32 | -------------------------------------------------------------------------------- /Day 5/22.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 11:44:43 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 22 9 | Write a program to compute the frequency of the words from the input. 10 | The output should output after sorting the key alphanumerically. 11 | Suppose the following input is supplied to the program: 12 | New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3. 13 | Then, the output should be: 14 | 2:2 15 | 3.:1 16 | 3?:1 17 | New:1 18 | Python:5 19 | Read:1 20 | and:1 21 | between:1 22 | choosing:1 23 | or:2 24 | to:1 25 | ''' 26 | input_str = "New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." 27 | li = input_str.split(" ") 28 | my_set = set(li) 29 | for item in sorted(my_set): 30 | print(f"{item}:{li.count(item)}") 31 | -------------------------------------------------------------------------------- /Day 5/23.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 12:47:56 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 23 9 | Write a method which can calculate square value of number 10 | ''' 11 | 12 | class CalSq(): 13 | def __init__(self): 14 | pass 15 | def square(self, num): 16 | return num**2 17 | 18 | print(CalSq().square(8)) 19 | -------------------------------------------------------------------------------- /Day 5/24.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 12:52:53 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 24 9 | Python has many built-in functions, and if you do not know how to use it, 10 | you can read document online or find some books. But Python has a built-in 11 | document function for every built-in functions. 12 | Please write a program to print some Python built-in functions documents, 13 | such as abs(), int(), raw_input() 14 | And add document for your own function 15 | Hints: 16 | The built-in document method is __doc__ 17 | ''' 18 | 19 | def cool_func(num): 20 | ''' 21 | Parameters 22 | ---------- 23 | num : int 24 | it is just a number. 25 | 26 | Returns 27 | ------- 28 | return True if the num is greater than 0, False otherwise 29 | ''' 30 | if num > 0: 31 | return True 32 | return False 33 | 34 | print(cool_func.__doc__) 35 | print(str.__doc__) -------------------------------------------------------------------------------- /Day 5/25.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Wed Sep 2 13:04:42 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 25 9 | Define a class, which have a class parameter and have a same instance parameter. 10 | ''' 11 | class MyClass(): 12 | name = "rohan" 13 | def __init__(self, name=None): 14 | self.name = name 15 | 16 | name = MyClass("saurabh") 17 | print(name) 18 | print(name.name) 19 | print(MyClass.name) 20 | print(MyClass) 21 | 22 | name2 = MyClass() 23 | name2.name = "Mohit" 24 | print(name2) 25 | print(name2.name) 26 | print(MyClass.name) -------------------------------------------------------------------------------- /Day 6/26.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 10:59:06 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 26 9 | Define a function which can compute the sum of two numbers. 10 | ''' 11 | sum = lambda n1,n2 : n1 + n2 12 | print(sum(1,2)) 13 | -------------------------------------------------------------------------------- /Day 6/27.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 10:59:58 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 27 9 | Define a function that can convert a integer into a string and print it in console. 10 | ''' 11 | def int_to_str(item): 12 | print(str(item)) 13 | 14 | int_to_str(45) 15 | 16 | ########################################### 17 | 18 | conversion = lambda x:str(x) 19 | print(conversion) 20 | print(type(conversion)) 21 | print(conversion(56)) 22 | print(type(conversion(56))) -------------------------------------------------------------------------------- /Day 6/28.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 11:03:56 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 28 9 | Define a function that can receive two integer numbers in string form 10 | and compute their sum and then print it in console. 11 | ''' 12 | 13 | conversion = lambda x,y:print(int(x) + int(y)) 14 | 15 | conversion("45","55") 16 | 17 | -------------------------------------------------------------------------------- /Day 6/29.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 11:06:32 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 29 9 | Define a function that can accept two strings as input and concatenate them 10 | and then print it in console. 11 | ''' 12 | concat = lambda x,y: print(x+y) 13 | concat("hello", "saurabh") 14 | -------------------------------------------------------------------------------- /Day 6/30.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 11:08:22 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 30 9 | Define a function that can accept two strings as input and print the string 10 | with maximum length in console. If two strings have the same length, 11 | then the function should print all strings line by line. 12 | ''' 13 | def max_string(x,y): 14 | if len(x) > len(y): 15 | print(x) 16 | elif len(x) == len(y): 17 | print(x) 18 | print(y) 19 | else: 20 | print(y) 21 | 22 | max_string("saurabh", "agarwal") 23 | 24 | ######################################### 25 | 26 | func = lambda a,b: print(max((a,b),key=len)) if len(a)!=len(b) else print(a+'\n'+b) 27 | func("hello","yoyoo") 28 | -------------------------------------------------------------------------------- /Day 7/31.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 11:15:44 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 31 9 | Define a function which can print a dictionary where the keys are numbers 10 | between 1 and 20 (both included) and the values are square of keys. 11 | ''' 12 | def sq_dict(): 13 | return {i:i*i for i in range(1,21)} 14 | 15 | print(sq_dict()) 16 | 17 | ##################################### 18 | 19 | print(dict(enumerate((i * i for i in range(1,21)),1))) 20 | -------------------------------------------------------------------------------- /Day 7/32.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Sep 3 11:27:00 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 32 9 | Define a function which can generate a dictionary where the keys are numbers 10 | between 1 and 20 (both included) and the values are square of keys. 11 | The function should just print the keys only. 12 | ''' 13 | def dict_func(): 14 | my_dict = dict(enumerate((i*i for i in range(1,21)),1)) 15 | print(my_dict.keys()) 16 | 17 | dict_func() 18 | -------------------------------------------------------------------------------- /Day 7/33.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Sep 5 11:02:39 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 33 9 | Define a function which can generate and print a list where the values are 10 | square of numbers between 1 and 20 (both included). 11 | ''' 12 | 13 | def sq_func(): 14 | li = [i**2 for i in range(1,21)] 15 | print(li) 16 | 17 | sq_func() 18 | -------------------------------------------------------------------------------- /Day 7/34.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Sep 5 11:04:52 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 34 9 | Define a function which can generate a list where the values are square of 10 | numbers between 1 and 20 (both included). Then the function needs to print 11 | the first 5 elements in the list. 12 | ''' 13 | def sq_func(elements): 14 | li = [i**2 for i in range(1,21)] 15 | print(li[0:elements]) 16 | 17 | 18 | sq_func(5) 19 | -------------------------------------------------------------------------------- /Day 7/35.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Sep 5 11:04:59 2020 4 | 5 | @author: saura 6 | """ 7 | ''' 8 | Question 35 9 | Define a function which can generate a list where the values are square of 10 | numbers between 1 and 20 (both included). Then the function needs to print the 11 | last 5 elements in the list. 12 | ''' 13 | def sq_func(elements): 14 | li = [i**2 for i in range(1,21)] 15 | print(li[-5:]) 16 | 17 | sq_func(5) 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | The exercise text contents of this repository was collected from GitHub account of [@darkprinx](https://github.com/darkprinx/100-plus-Python-programming-exercises-extended), who himself had collected them from the GitHub account of [@zhiwehu](https://github.com/zhiwehu/Python-programming-exercises). 3 | 4 | I collected it to practice and solve all the listed problems with python. Even after these collected problems are all set up, I will try to add more problems in near future. 5 | For every problem, I have added my solution at the top, followed by some other unique and good solutions which I found in the above said repository. 6 | 7 | I have divided the 100 exercises into 20 days, with each day carrying 5 excercises. 8 | 9 | If you are a beginner with python then I hope these exercises will help you immensely, just the way they did to me :) 10 | 11 | Thank You, and have fun! 12 | --------------------------------------------------------------------------------