├── Python Assignment ├── Day_10_List.pdf ├── Day_11_Introduction_to_lists_Indexing_and_slicing_in_lists_List_Comprehension.pdf ├── Day_12_Function.pdf ├── Day_13__Recursive_Function.pdf ├── Day_14_Yield_Statement.pdf ├── Day_15_2D_List.pdf ├── Day_16_Python_String.pdf ├── Day_18_Searching_Algorithm_Assignment.pdf ├── Day_19_File_Handling_Level_-_1.pdf ├── Day_20_File_Handling_Level_-_2.pdf ├── Day_2__Variables_Data_Types_Input__Output_Statement_and_F-String.pdf ├── Day_3_Arithmetic_Operator.pdf ├── Day_4__Comparison_Operators.pdf ├── Day_5_Conditional_Statements.pdf ├── Day_6_Logical_Operators.pdf ├── Day_7_While_Loop.pdf ├── Day_8_For_Loop.pdf ├── Day_9_Nested_Loop.pdf ├── ST-2_Assignment.pdf └── Student_Task_Python_Conditional_Statements.pdf ├── Standard Notes └── link.txt ├── Unit 1 ├── Sprint 1 │ ├── Day 1 │ │ └── notes.txt │ ├── Day 2 │ │ └── firstProgram.py │ └── Day 3 │ │ └── introductionToPythonVariable.py ├── Sprint 2 │ ├── Day 1 │ │ ├── inputOutputStatementExample.py │ │ └── introductionPythonDataTypes.py │ ├── Day 2 │ │ ├── fStringExample.py │ │ └── moreAboutInputOutputStatementExample.py │ └── Day 3 │ │ ├── arithmeticOperatorExample.py │ │ ├── dataAllocationInMemoryExample.py │ │ ├── outputStatementExample.py │ │ └── recap.notes ├── Sprint 3 │ ├── Day 1 │ │ ├── Arithmetic_Operator_Precedence_and_Associativity_in_Python.pdf │ │ ├── Student_Activity_Arithmetic_Operator_Precedence_and_Associativity.pdf │ │ ├── comparisonOperatorExample.py │ │ └── moreAboutMathematicalOperators.py │ ├── Day 2 │ │ └── conditionalStatementExample.py │ ├── Day 3 │ │ ├── logicalOperatorExample.py │ │ └── moreAboutConditionalStatementExample.py │ └── Day 4 │ │ ├── introductionToLoopExample.py │ │ ├── moreAboutLogicalOperatorExample.py │ │ └── ternaryOperatorExample.py └── Sprint 4 │ ├── Day 1 │ └── notes.txt │ ├── Day 2 │ └── recapingLoopExample.py │ ├── Day 3 │ ├── breakAndContinueStatement.py │ ├── forLoopExample.py │ └── moreAboutWhileLoopExample.py │ └── Day 4 │ ├── moreExamplesUsingForLoop.py │ └── nestedLoopExample.py ├── Unit 2 ├── Sprint 1 │ ├── Day 1 │ │ ├── introductionPythonListExample.py │ │ └── moreAboutNestedLoopExample.py │ └── Day 2 │ │ └── moreAboutListExample.py ├── Sprint 2 │ ├── Day 1 │ │ ├── introductionToFunctionExample.py │ │ └── slicingAndListComprehensionExample.py │ ├── Day 2 │ │ ├── aboutpasskeywordExample.py │ │ └── moreAboutFunctionExample.py │ ├── Day 3 │ │ ├── breakVsReturnExample.py │ │ ├── iteratorExample.py │ │ ├── moreAboutFunctionExample.py │ │ └── yieldStatementAndGeneratorFunctionExample.py │ └── Day 4 │ │ ├── introductionToRecursiveFunctionExample.py │ │ └── lambdaFunctionExample.py ├── Sprint 3 │ ├── Day 1 │ │ └── notes.txt │ ├── Day 2 │ │ └── introductionTo2DList.py │ ├── Day 3 │ │ └── notes.txt │ └── Day 4 │ │ └── moreAbout2DListExample.py └── Sprint 4 │ └── Day 1 │ └── 2DListExamples.py ├── Unit 3 ├── Sprint 1 │ ├── Day 1 │ │ └── introductionToStringExample.py │ ├── Day 2 │ │ ├── StringInbuiltFunctionExample.py │ │ └── notepadApplicationFuncitionalityExample.py │ ├── Day 3 │ │ └── introductionToTupleExample.py │ ├── Day 4 │ │ ├── introductionToDictionaryExample.py │ │ └── introductionToSetExample.py │ └── Day 5 │ │ └── moreAboutDictionaryExample.py ├── Sprint 2 │ └── Day 1 │ │ └── moreAboutDictionaryExample.py ├── Sprint 3 │ ├── Day 1 │ │ └── moreAboutDictionaryExample.py │ ├── Day 2 │ │ └── moreAboutDictionaryExample.py │ └── Day 3 │ │ └── recap.py └── Sprint 4 │ ├── Day 1 │ ├── inputTakingExample.py │ ├── introductionToSortingAlgorithms.py │ └── selectionSortAlgorithmExample.py │ ├── Day 2 │ ├── binarySearchAlgorithmExample.py │ ├── bubbleSortAlgorithmExample.py │ ├── introductionToSearchingAlgorithm.py │ └── linearSearchAlgorithmExample.py │ └── Day 3 │ ├── data.txt │ ├── fileHandlingExample.py │ ├── note.txt │ ├── uniqueIdGenerationExample.py │ └── whyFileHandlingInPython.py └── Unit 4 ├── Sprint 1 ├── Day 1 │ ├── data.txt │ ├── data1.txt │ ├── moreAboutFilesExample.py │ └── students.txt ├── Day 2 │ ├── fileRecap.py │ ├── introductionToObjectOrientedProgramming.py │ ├── studentRegistrationSystem.py │ └── students.json ├── Day 3 │ └── moreAboutObjectOrientedProgrammingExample.py └── Day 4 │ └── moreAboutObjectOrientedProgrammingExample.py ├── Sprint 2 └── Day 1 │ ├── data.txt │ └── introductionToExceptionHandlingExample.py └── Sprint 3 ├── Day 1 ├── LabelExample.py └── introductionToTkinter.py └── Day 2 ├── buttonExample.py ├── data.json ├── entryExample.py ├── frameExample.py ├── layoutManagementFunctionExample.py ├── radioButtonExample.py └── tkinterVariables.py /Python Assignment/Day_10_List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_10_List.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_11_Introduction_to_lists_Indexing_and_slicing_in_lists_List_Comprehension.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_11_Introduction_to_lists_Indexing_and_slicing_in_lists_List_Comprehension.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_12_Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_12_Function.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_13__Recursive_Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_13__Recursive_Function.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_14_Yield_Statement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_14_Yield_Statement.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_15_2D_List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_15_2D_List.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_16_Python_String.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_16_Python_String.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_18_Searching_Algorithm_Assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_18_Searching_Algorithm_Assignment.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_19_File_Handling_Level_-_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_19_File_Handling_Level_-_1.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_20_File_Handling_Level_-_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_20_File_Handling_Level_-_2.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_2__Variables_Data_Types_Input__Output_Statement_and_F-String.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_2__Variables_Data_Types_Input__Output_Statement_and_F-String.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_3_Arithmetic_Operator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_3_Arithmetic_Operator.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_4__Comparison_Operators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_4__Comparison_Operators.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_5_Conditional_Statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_5_Conditional_Statements.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_6_Logical_Operators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_6_Logical_Operators.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_7_While_Loop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_7_While_Loop.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_8_For_Loop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_8_For_Loop.pdf -------------------------------------------------------------------------------- /Python Assignment/Day_9_Nested_Loop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Day_9_Nested_Loop.pdf -------------------------------------------------------------------------------- /Python Assignment/ST-2_Assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/ST-2_Assignment.pdf -------------------------------------------------------------------------------- /Python Assignment/Student_Task_Python_Conditional_Statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Python Assignment/Student_Task_Python_Conditional_Statements.pdf -------------------------------------------------------------------------------- /Standard Notes/link.txt: -------------------------------------------------------------------------------- 1 | https://typical-saguaro-5f8.notion.site/Python-Notes-1069ea19b39780c59571e013ae8ad0de?pvs=4 -------------------------------------------------------------------------------- /Unit 1/Sprint 1/Day 1/notes.txt: -------------------------------------------------------------------------------- 1 | Introduction to Python -------------------------------------------------------------------------------- /Unit 1/Sprint 1/Day 2/firstProgram.py: -------------------------------------------------------------------------------- 1 | #print("Hello World!") 2 | #print("Welcome to Python Session") 3 | #print("349234392793427934") 4 | 5 | #below we're creating student report card 6 | 7 | print("--**--**----**--**----**--**----**--**----**--**--") 8 | print("| Chitkara University |") 9 | print("| |") 10 | print("--**--**----**--**----**--**----**--**----**--**--") 11 | -------------------------------------------------------------------------------- /Unit 1/Sprint 1/Day 3/introductionToPythonVariable.py: -------------------------------------------------------------------------------- 1 | #Single Line Comment: tells about what particular lines of code is all about. 2 | 3 | #Variable: it is like a container/box which is used to store some technical/virtual data. 4 | 5 | #technical data: it is colletion of numbers and words 6 | 7 | #Numbers: 1. integer numbers(+ve(23, 34, 89098), -ve(-45,-675,-690)), 2. decimal number(456.56, 34232.00045(float number)) 8 | #Real Life Examples: customerAge = 34, orderCount=45,salary=98789.67, ITDepartmentSalary=45434.4534 9 | 10 | #Words(Strings): It is collections of characters(numbers + letters+ special symbols) enclosed with single ('') or double duatation marks ("") 11 | #Real Life Examples: customerName = "Bob Singh", address = "Nand Colony Sector 73", username = "bob@1234", password = "bob123434@", pincode = "201301" 12 | 13 | 14 | #Declaration is also known as creating/making something. 15 | 16 | 17 | #Declaration/creation/defining of variable 18 | #Syntax: how to use particular concept in python, please don't be the friend of syntax. 19 | #varible_name 20 | 21 | 22 | #Examples 23 | 24 | #pictures 25 | #age 26 | 27 | #Note: it is important to initialize/store/add value to the variable at the time of declaration. 28 | 29 | #how to store/initilize/add value to the variable: = (sign/operator): assignment operator - it is used to assign/store value to the variable. 30 | 31 | # pictures = "Annual Function Award" 32 | # name = "Shivani" 33 | # age = 23 34 | 35 | #Note: left side of assignment operator(=) is always variable and right side of this assignment operator(=) is always value. 36 | 37 | 38 | #how to check what is there inside paticular variable: print() - its like a tool which helps us to print something on console. 39 | #print(variable_name) 40 | 41 | # print(pictures) 42 | # print(name) 43 | # print(name, age) 44 | # print("Shivani", age) 45 | # print("Hello, I'm",name, "and",age, "years", "olds.") 46 | 47 | 48 | #Rules for taking valid variable name 49 | 50 | #1. Start with a letter or underscore (_) 51 | 52 | #1name #invalid variable name as it is starting with number 53 | #$age #invalid variable name as it is starting with special symbol($) 54 | #_age #valid variable name as it is starting with underscore(_) 55 | #fatherName #valid variable name as it is starting with letter. 56 | 57 | #2. Can contain letters, numbers, and underscores. 58 | 59 | #father name #invalid variable name as it is containing space 60 | #age$ #invalid variable name as it is containing $ 61 | #father_name #valid variable name as it is containing underscore and letters. 62 | 63 | #3. Case-sensitive, myVar, and myvar are considered different variables. 64 | 65 | #4. Avoid using Python-reserved words as variable names like while, if, and 66 | 67 | #class #invalid variable name as it is python pre-defined word which is having some functionality. 68 | #Class #valid variable name 69 | #if #invalid variable name as it is python pre-defined work which has certain functionality 70 | 71 | #5. At the time of declaration of a variable its important to Initialize it. 72 | 73 | #---------------------------------------------------------------- 74 | #VariableNamingConvention: so that, you can create meaningful variable names. 75 | 76 | #Note: if your variable name is single worded, then naming convention rules don't apply like: 77 | 78 | name = "Thapa" 79 | age = 34 80 | 81 | #What if when we have multi-word variable name, for this we've two types of naming convetion which are given follow. 82 | 83 | 84 | #camelCaseNamingConvention: 85 | 86 | fatherName 87 | firstName 88 | customerName 89 | myClassTeacherName 90 | 91 | #snack_case_naming_convention 92 | 93 | father_name 94 | first_name 95 | customer_name 96 | employee_name 97 | employee_age 98 | my_class_teacher_name 99 | 100 | -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 1/inputOutputStatementExample.py: -------------------------------------------------------------------------------- 1 | #input statement: it is used to take input from user, it always gives you entered value in the form of string 2 | #syntax: input("Enter Your Name:") 3 | 4 | name = input("Enter Your Name:") 5 | 6 | #output Statement: to print/show the entered value using print(varible_name) 7 | 8 | print("Your Name is:", name) -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 1/introductionPythonDataTypes.py: -------------------------------------------------------------------------------- 1 | #Data Types: What kind of value/data, a variable is storing is known as Data Types. 2 | 3 | name = "Value" 4 | 5 | #How will you know what kind of data a variable is storing? : through variable's value. 6 | 7 | #Primitive Data Type: 8 | #such variabels those are holiding primitive data types are knowns primitive variables 9 | #It stores one value at a time, there are following types of primitive data types: 10 | 11 | #int: it can be either negative numebr or positive number 12 | 13 | # age = 45 14 | # print(age) 15 | 16 | #How to check data types of a variable? : type() 17 | #syntax: type(variable_name) 18 | 19 | # print(type(age)) 20 | 21 | #float: it is decimal number 22 | 23 | # totalBill = 456.90 24 | # print("Total Bill", totalBill) 25 | # print(type(totalBill)) 26 | 27 | #string: it is sequence/collection of characters(numberrs + letter + special symbols) enclosed with single or double quatation marks. 28 | 29 | # favoriteLetter = 'a' 30 | # print(favoriteLetter) 31 | # print(type(favoriteLetter)) 32 | 33 | # fatherName = "Ramesh Kumar" 34 | 35 | # print(fatherName) 36 | # print(type(fatherName)) 37 | 38 | #Hi, I'm Shreya from Delhi and learning 'Python Programming Language'. 39 | 40 | # sentence = "Hi, I'm Shreya from Delhi and learning 'Python Programming Language'." 41 | 42 | # print(sentence) 43 | # print(type(sentence)) 44 | 45 | #Boolean: it can have either True or False where True is known as Yes/Hai and False is known as No/Na 46 | 47 | isMarried = True 48 | isFriday = False 49 | print(isMarried) 50 | print(isFriday) 51 | 52 | print(type(isMarried)) 53 | print(type(isFriday)) -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 2/fStringExample.py: -------------------------------------------------------------------------------- 1 | # #F-String: using this concept, you can directly use/embed variable and expression into the string. 2 | 3 | # #life with f string 4 | 5 | # # name = "Alice" 6 | # # age = 45 7 | # # #Hi, I'm Alice and I'm 45 years old. 8 | # # print("Hi, I'm", name, "and I'm", age, "years old.") 9 | 10 | # # #using F-String 11 | # # print(f"Hi, I'm {name} and I'm {age} years old.") 12 | 13 | # #Good Example 1: Create Dynamic Email 14 | 15 | # # email = " 16 | # # Dear Rakesh 17 | 18 | # # I'm from Masai, where i will teach you about Python Programming Languange. 19 | 20 | # # Best Regards 21 | # # Anand Singh Yadav 22 | # # " 23 | 24 | # #Note: if you're creating multi-line string using double quatation mark then it will give you error then what is the solution for multi-line string: triple quatation marks(""" """) 25 | 26 | # #triple quatation marks(""" """): 27 | # # your python doesn't support multi-line comment, but you can use below method to keep multi line comment but this is not recommended. 28 | # #You can use it for creating multi-line string. 29 | 30 | # studentName = input("Enter Student Name: ") 31 | # teacherOrg = input("Enter Teacher Organization: ") 32 | # programmingLanguange = input("Ente Programming Language: ") 33 | # teacherName = input("Enter Teacher Name: ") 34 | 35 | # email = f""" 36 | # Dear {studentName} 37 | 38 | # I'm from {teacherOrg}, where i will teach you about {programmingLanguange} Programming Languange. 39 | 40 | # Best Regards 41 | # {teacherName} 42 | # """ 43 | 44 | # print(email) 45 | 46 | -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 2/moreAboutInputOutputStatementExample.py: -------------------------------------------------------------------------------- 1 | #Good Example 1: take, name, age, and city from user and print on the console. 2 | 3 | #taking input from user 4 | # name = input("Enter Name: ") 5 | # age = input("Enter Age: ") 6 | # city = input("Enter City: ") 7 | 8 | #printing the value 9 | # print("User Name:", name) 10 | # print("User Age:", age) 11 | # print("User City:", city) 12 | 13 | #The data you're getting from input() function, do you know the type of data? 14 | 15 | # print("Type of Name Value:", type(name)) 16 | # print("Type of City Value:", type(city)) 17 | # print("Type of Age Value:", type(age)) 18 | 19 | #I want to convert string to integer and integer to float. 20 | #Type Conversion: you convert type of data to another type. 21 | 22 | #Example 1: 23 | # age = 45 24 | # ageToFloat = float(age) 25 | # ageToString = str(age) 26 | # print(age, type(age)) # 27 | # print(ageToFloat, type(ageToFloat)) # 28 | # print(ageToString, type(ageToString)) # 29 | 30 | # #Example 2: 31 | 32 | # value = "45" 33 | # intValue = int(value) 34 | # floatValue = float(value) 35 | # print(value, type(value)) # 36 | # print(intValue, type(intValue)) # 37 | # print(floatValue, type(floatValue)) # 38 | 39 | #Good Example 2: take, name, age, and city from user and print on the console. 40 | 41 | #taking input from user 42 | # name = input("Enter Name: ") 43 | # age = int(input("Enter Age: ")) 44 | # city = input("Enter City: ") 45 | 46 | #printing the value 47 | # print("User Name:", name) 48 | # print("User Age:", age, type(age)) 49 | # print("User City:", city) 50 | 51 | #Create 52 | # Dynamic Report Card: 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 3/arithmeticOperatorExample.py: -------------------------------------------------------------------------------- 1 | #Arithmetic/Mathematical Operator: it is used to perform some mathematical calculation/operations on numberic data values. 2 | 3 | #There are following types of Arithematic Operators: 4 | # +(addition), -(subtraction), * (multiplicaiton), /(division), //(Floor Division: Quotient), **(exponent) 5 | 6 | #Note: Operator(+, -, *, /, //, **) always operates with operands(data values) 7 | #In other word: particular operator will perform particular operation with variables data, it alwaysa return some resultant value. 8 | 9 | #Examples: 10 | 11 | # a = 20 12 | # b = 10 13 | 14 | # #Addition 15 | # #Operator: + 16 | # #Operands: a and b 17 | # # add = a + b 18 | # # print(add) 19 | # print(a+b) #30 20 | 21 | # #Subtraction 22 | # print(a-b) #10 23 | 24 | # #Multiplication 25 | # print(a * b) #200 26 | 27 | # #Division(/): it returns result in float type. 28 | # print(a / b) #2.0 29 | 30 | # #Floor Division(//): it always return integer value. 31 | # print(a//b) #2 32 | 33 | # #Exponent(**): its used to find any power of any number 34 | 35 | # #Without Exponent 36 | # print(5*5) #25 37 | # print(5*5*5) #125 38 | 39 | # #What if i ask to find the 2^10 40 | # print(2*2*2*2*2*2*2*2*2*2) 41 | 42 | # #In this way, you're writing duplicate code or you can your program has redundancy/duplicacy: what is the solution - exponent operator 43 | 44 | # print(2**2) #4 45 | # print(4**3) #64 46 | 47 | # #Good Example 1: Creata a program where take two integer number input from user and display the sum, multiplication, division, and subtraction. 48 | 49 | # # num1 = int(input("Enter Number 1: ")) 50 | # # num2 = int(input("Enter Number 2: ")) 51 | 52 | # # print("Sum of num1 and num2: ", num1 + num2) 53 | # # print("Multiplication of num1 and num2: ", num1 * num2) 54 | # # print("Difference of num1 and num2: ", num1 - num2) 55 | # # print("Division of num1 and num2: ", num1 / num2) 56 | 57 | # #Good Example 2: A 30% discount offer is going on flipkart, if you will buy any three products with each product has atleast 3 quantity, your task is to find the payable price after discount according to following data. 58 | 59 | # product1Price = 500 60 | # product2Price = 200 61 | # product3Price = 1000 62 | 63 | # product1Quantity = 5 64 | # product2Quantity = 3 65 | # product3Quantity = 4 66 | 67 | # totalBill = product1Price * product1Quantity + product2Price * product2Quantity + product3Price * product3Quantity 68 | 69 | # print("Total Bill: ", totalBill) 70 | 71 | # discount = totalBill * 30/100 72 | 73 | # print("Discount on Total Bill: ", discount) 74 | 75 | # print("Payable Price", totalBill - discount) 76 | 77 | 78 | #Mathematical Expression: 79 | a,b,c = 2, 3, 5 80 | 81 | 82 | -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 3/dataAllocationInMemoryExample.py: -------------------------------------------------------------------------------- 1 | name = "Tanisha" -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 3/outputStatementExample.py: -------------------------------------------------------------------------------- 1 | #output statement: to display msg/output to the user, that's why we use output statement. 2 | 3 | print("Welcome to Another Session of Python") 4 | 5 | #sep: its parameter where you can sperate particular strings by some seperator. 6 | #end: its parameter it is used to print/add something at the end of string. 7 | 8 | 9 | print("Java", "Python", "Javascript", sep=" : ") 10 | print("Java", "Python", "Javascript", sep=" language ") 11 | print("Java", "Python", "Javascript", sep=" language ", end=" language ") -------------------------------------------------------------------------------- /Unit 1/Sprint 2/Day 3/recap.notes: -------------------------------------------------------------------------------- 1 | Variables: its like a container 2 | Data Types: Type of data a variables is holding. 3 | Classification of Data Types: 4 | 1. Number 5 | int: integer(-45, 56) 6 | float: decimal number/floating numbers(45.56, 56.67) 7 | boolean: Either True or False 8 | complex: not in your syllabus 9 | 2. Sequence 10 | String: it can be either in '' or in "" or in """ """ 11 | List: Discuss later 12 | Tuple: Discuss later 13 | 3. Mapping: 14 | Dictionary: Discuss later 15 | 4. Set: 16 | set: Discuss later 17 | 5. None: 18 | None: Discuss later 19 | 20 | name = "Rakesh" 21 | age = 34 22 | city = "Delhi" 23 | 24 | Stack Heap(values) 25 | |45342323232| ----------- | "Rakesh"|(object) 26 | name 27 | 28 | |54534232323| ----------- | 34 | (object) 29 | age 30 | 31 | |545342s4532323| ----------- | "Delhi" | (object) 32 | city 33 | 34 | num1 = 45 35 | num2 = 45 36 | 37 | Stack Heap 38 | |453434342323| -------------| 45 |(object) 39 | num1 40 | num2 41 | 42 | How variables are allocated some space in the memory? 43 | -During execution of your program, some process(program) will occupy some space in the RAM that occupied space is known as Address Space. 44 | 45 | This Address has following parts: 46 | 47 | 1. Data Segment: it contains variables and values which has following two parts. 48 | A. Stack: 49 | -the memory occupied in stack, you can provide any user friendly name, so that you can access tha value at the address/reference. 50 | -the memory allocation in stack, you can not resized. 51 | - the memory allocated in stack, it takes place in the memory statically. 52 | B. Heap: 53 | -the memory occupied in heap,you can't provide any name, it only stores object 54 | -the memory allocation in heap, you can resized. 55 | - the memory allocated in heap, it takes place in the memory Dynamically. -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 1/Arithmetic_Operator_Precedence_and_Associativity_in_Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Unit 1/Sprint 3/Day 1/Arithmetic_Operator_Precedence_and_Associativity_in_Python.pdf -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 1/Student_Activity_Arithmetic_Operator_Precedence_and_Associativity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Unit 1/Sprint 3/Day 1/Student_Activity_Arithmetic_Operator_Precedence_and_Associativity.pdf -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 1/comparisonOperatorExample.py: -------------------------------------------------------------------------------- 1 | # Comparison Operator: it compare same and different type of value, or you can use it to create conditions. 2 | #Note: whenever we compare two different value that kind of comparison is known as condition or criteria 3 | #-Comparison operator always returns Boolean value (Either True or False) 4 | 5 | #There are following types of Comparison Operators: 6 | #Operators: 7 | #1. <(less than): it returns true once first value is greater than 8 | #2. >(greater than): it returns true once first value is less than 9 | #3. <=(less than or equal to): it returns true once first value is greater than or equal to other value 10 | #4. >=(greater than or equal to): it returns true once first value is less than or eqaul to other value. 11 | #5. == (double equalt to): to check equality 12 | #6. !=(not equal to): to not check equality 13 | 14 | #Examples: check a number is negative or positive 15 | 16 | num = 34 17 | #conditionToCheckNegativeNumber = num < 0 18 | #print(conditionToCheckNegativeNumber) #False 19 | 20 | #Case 1: less than 21 | print(num < 0) #False 22 | #False: Number is positive 23 | #True: Number is negative 24 | 25 | #Case 2: greater than 26 | print(num > 0) #True 27 | #True: Number is positive 28 | #False: Number is negative 29 | 30 | #Example 2: check a number is greater or eqaul to 31 | 32 | # num1 = 60 33 | # num2 = 60 34 | 35 | # print(num1 > num2) #False 36 | # print(num1 < num2) #False 37 | 38 | # print(num1 >= num2) #True 39 | # print(num1 <= num2) #True 40 | 41 | 42 | #5. == (double equal to): to compare/check equality 43 | #5. != (not equal to): to compare/check not equality 44 | 45 | #Example: check a number is equal to another number or not 46 | 47 | # num1 = 45 48 | # num2 = 56 49 | 50 | # print(num1 == num2) #False 51 | # print(num1 != num2) #True 52 | 53 | # #Let's compare now with different types of value 54 | 55 | # #Exmaple: 56 | # name1 = "Prince" 57 | # name2 = "Rohan" 58 | 59 | # print(name1 == name2) #False 60 | # print(name1 != name2) #True 61 | 62 | # print(45 == "45") #False 63 | # print(45 != "45") #True 64 | 65 | 66 | # print(True == 1) #True 67 | # print(False == 0) #True 68 | 69 | #Note: when you've numeric types of data to compare then only proceed with <, >, <=, >= operators, if you've mix kind of data to compare then proceed with ==, != 70 | 71 | 72 | #Good Example 1: Take a number from the user using input statement and check that number is odd or even. 73 | 74 | # num = int(input("Enter Number: ")) 75 | 76 | # print(num % 2==0) #True 77 | # #True: Number is even 78 | # #False: Number is odd 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 1/moreAboutMathematicalOperators.py: -------------------------------------------------------------------------------- 1 | # #Mathematical Expression: 2 | # a,b,c,d = 3, 5, 2, 4 3 | 4 | # result = a**c + 2*d + (a*b) - d + a 5 | # print(result) 6 | 7 | 8 | # #Addition with String type of data. 9 | 10 | # print( 2+2) 11 | # print("Hello" + " " + "World") 12 | # print("34" + "2") 13 | 14 | # #True: 1 15 | # #False: 0 16 | # print(True + 1) # 2 17 | # print(False + 1) # 1 -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 2/conditionalStatementExample.py: -------------------------------------------------------------------------------- 1 | #Conditional Statement: Why are we learning? 2 | #Reason: So that on the basis of particular condition you can provide meaningful statement/msg to the user/customer. 3 | 4 | #How to create condition? - Using Comparison Operator 5 | #Examples: 6 | 7 | #Create condition to check age is greater or eqault to 18 8 | # age = 19 9 | # print(age >= 18) #True 10 | 11 | # #Create conditon to check number is even or odd 12 | # num = 45 13 | # print(num%2==0) #False 14 | 15 | 16 | #In the case of Comparison opeartor, it always returns Boolean value that is 110% understandable by developer and your python but your cusotmer/user doesn't understand it. 17 | 18 | #There are following types of conditional statement in python: 19 | #1. if statement 20 | #2. if else statement 21 | #3. if elif else statement 22 | 23 | 24 | #1. if statement: if the given the condition is true then the code/statement inside if block will execute and if the condition is false then the code/statement inside if block will not execute. 25 | 26 | """ 27 | syntax: 28 | 29 | if condition: 30 | print("If condition is true") 31 | 32 | """ 33 | 34 | #Note: Python is indendation oriented programming language therefore for particular concept like conditional statements, loop, functions and other important concepts you need to use proper indendation. 35 | 36 | #Example 1: Check a number is negative or positive 37 | 38 | # num = 56 39 | 40 | # #conditionToCheckNegativeNumber = num < 0 41 | # # print(conditionToCheckNegativeNumber) #False 42 | # #if statement 43 | 44 | # if num < 0: 45 | # print("Starting of if block") 46 | # print("Number is negative") 47 | # print("Ending of if block") 48 | 49 | # print("Out side the if block") 50 | 51 | 52 | #Example 2: create a condition to check person is eligible for voting or not. 53 | 54 | # age = 19 55 | 56 | # # if False: 57 | # # print("Eligible for voting") #unreachable code 58 | 59 | # if age >= 18: 60 | # print("Eligible for voting.") 61 | 62 | #Example 3: create a problem to check username is correct or not. 63 | 64 | # username = input("Enter Username: ") 65 | 66 | # if username =="admin": 67 | # print("Logged in Successfully.") 68 | 69 | 70 | #Limitation of if statement: it always run the code inside if block if the condition is true it never runs anything if the condition is false, in this way it can hamper the user experience. 71 | 72 | 73 | #if you want to give msg on false condition then if statement is not the best choice then what is the best choice: if else statement. 74 | 75 | #2. if else statement: if the given the condition is true then the code inside if block will execute and if the condition is false then code inside else block will execute. 76 | 77 | """ 78 | syntax: 79 | 80 | if condition: 81 | print("If condition is true") 82 | else: 83 | print("If the condition is false") 84 | 85 | """ 86 | 87 | #Example 1: check a number is even or odd 88 | 89 | # num = int(input("Enter Number: ")) 90 | 91 | # if num%2==0: 92 | # print("Even Number") 93 | # else: 94 | # print("Odd Number") 95 | 96 | #Example 2: check any person username to login and give proper msg on invalid username 97 | 98 | # username = input("Enter Username: ") 99 | 100 | # if username == "admin": 101 | # print("Logged in successfully.") 102 | # else: 103 | # print("Invalid Username") 104 | 105 | #Exmaple: check a number is negative, positive or zero. 106 | 107 | #Limitation if else statement: if else statement is the best choice if you've only one condition. 108 | #because in the case of more conditions, you need create nested else if statement 109 | 110 | #Exmaple: check a number is negative, positive or zero. 111 | #using if statement: 112 | 113 | num = 56 114 | if num == 0: 115 | print("Number is zero.") 116 | else: 117 | if num > 0: 118 | print("Number is positive.") 119 | else: 120 | print("Number is negative.") 121 | 122 | 123 | #Example 2: print dayName on the basis of dayNumber where day 1 is as Monday. 124 | #Conditions to print correct dayname: 7 125 | 126 | # dayNumber = int(input("Enter Day Number: ")) 127 | 128 | # if dayNumber==1: 129 | # print("Monday") 130 | # else: 131 | # if dayNumber ==2: 132 | # print("Tuesday") 133 | # else: 134 | # if dayNumber ==3: 135 | # print("Wednesday") 136 | # else: 137 | # if dayNumber ==4: 138 | # print("Thursday") 139 | # else: 140 | # if dayNumber ==5: 141 | # print("Friday") 142 | # else: 143 | # if dayNumber ==6: 144 | # print("Saturday") 145 | # else: 146 | # if dayNumber==7: 147 | # print("Sunday") 148 | # else: 149 | # print("Invalid Day Number") 150 | 151 | #According to abvoe problem, if you will solve using if else statement it will make your code less readable and harder to mantain then what is the solution to create more readable and easy to maintain code. 152 | 153 | #3. if elif else statement: if you've more than one independent conditions then you can proceed with if elif statement. 154 | # among many conditions if any of the condition is true then code inside particular block will execute otherwise code insde else block will execute. 155 | 156 | """ 157 | syntax: 158 | 159 | if condition1: 160 | print("If condition1 is true") 161 | elif condition2: 162 | print("If condition2 is true") 163 | elif condition2: 164 | print("If condition3 is true") 165 | elif condition3: 166 | print("If condition4 is true") 167 | elif condition4: 168 | print("If condition5 is true") 169 | elif condition5: 170 | print("If condition6 is true") 171 | else: 172 | print("if any of the codition is not true") 173 | 174 | """ 175 | 176 | 177 | #Example: print dayName with the help of dayNumber where dayNumber 1 as Monday 178 | 179 | dayNumber = int(input("Enter Day Number: ")) 180 | 181 | if dayNumber ==1: 182 | print("Monday") 183 | elif dayNumber == 2: 184 | print("Tuesday") 185 | elif dayNumber == 3: 186 | print("Wednesday") 187 | elif dayNumber == 4: 188 | print("Thursday") 189 | elif dayNumber == 5: 190 | print("Friday") 191 | elif dayNumber == 6: 192 | print("Saturday") 193 | elif dayNumber == 7: 194 | print("Sunday") 195 | else: 196 | print("Invalid Day Number") 197 | 198 | 199 | -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 3/logicalOperatorExample.py: -------------------------------------------------------------------------------- 1 | #Logical Operator: it is the best choice if you've more than one related/dependent conditons or non related/independent conditons. 2 | 3 | #There are following type of logical Operators: 4 | #1. and 5 | #2. or 6 | #3. not 7 | 8 | #1. and: if all the given conditions are true then the entire expression will be true if any of the condition is false then entire expression will be false. 9 | 10 | """ 11 | syntax: 12 | condition1 and condtion2 and condition3 and condition4 13 | 14 | A B A and B 15 | True True True 16 | True False False 17 | False True False 18 | False False False 19 | 20 | Note: and operator always find its next True, if anywhere it finds False then it makes the entire expression as False. 21 | 22 | """ 23 | 24 | #Problem 2: user will enter username and password you need to print based on below data. 25 | # if username and password is correct print "Logged In Succcessfully" 26 | # if incorrect print "Invalid Username" or "Inavalid Password" according to the situation. 27 | 28 | #Without Using Logical and Operator: 29 | 30 | username= input("Enter Username: ") 31 | password= input("Enter Password: ") 32 | 33 | # if username == "admin": 34 | # if password == "12345": 35 | # print("Logged In Successfully") 36 | # else: 37 | # print("Invalid Password") 38 | # else: 39 | # print("Invalid Username") 40 | 41 | #Using Logical Operator 42 | 43 | if username == "admin" and password == "12345": 44 | print("Logged In Successfully.") 45 | else: 46 | print("Invalid Credential") -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 3/moreAboutConditionalStatementExample.py: -------------------------------------------------------------------------------- 1 | #Probblem 1: create a program to check a letter is vowel or consonant. 2 | #vowels: a,e,i,o,u 3 | #Solution: using if elif else statemnt 4 | 5 | #if statement: best when you've one condition and want to test for true condition 6 | #if else statement: best for one condtion if you want to test particular condition for both true and false. 7 | #if elif else statment: best when you've more than one condition. 8 | 9 | # letter = input("Enter Any Alphabet: ") 10 | 11 | # if letter == "a": 12 | # print("Vowel") 13 | # elif letter == "e": 14 | # print("Vowel") 15 | # elif letter == "i": 16 | # print("Vowel") 17 | # elif letter == "o": 18 | # print("Vowel") 19 | # elif letter == "u": 20 | # print("Vowel") 21 | # else: 22 | # print("Consonant") 23 | 24 | #Problem 2: user will enter username and password you need to print based on below data. 25 | # if username and password is correct print "Logged In Succcessfully" 26 | # if incorrect print "Invalid Username" or "Inavalid Password" according to the situation. 27 | 28 | #Note: when your one condition is connected/dependent on another condition then in this case, you can proceed with nest if else statement. 29 | 30 | #Nested if statement: when one condition is connected to another condition 31 | #if inside another if 32 | 33 | """ 34 | syntax: 35 | 36 | if condition1: 37 | #once condition1 is true 38 | if condition2: 39 | #once condition2 is true 40 | if condition3: 41 | #once condition3 is true 42 | else: 43 | #once condition3 is false 44 | else: 45 | #once condition2 is false 46 | else: 47 | #once condition1 is false 48 | 49 | """ 50 | 51 | # username= input("Enter Username: ") 52 | # password= input("Enter Password: ") 53 | 54 | # if username == "admin": 55 | # if password == "12345": 56 | # print("Logged In Successfully") 57 | # else: 58 | # print("Invalid Password") 59 | # else: 60 | # print("Invalid Username") 61 | 62 | 63 | #Problem 2: print "Selected for Job" according to below criteria 64 | #degree="mca", percentage>=80, isDSA=true 65 | 66 | # degree = "mca" 67 | # percentage = 80 68 | # isDSA = True 69 | 70 | # if degree == "mca": 71 | # if percentage >= 80: 72 | # if isDSA: 73 | # print("Selected for Job") 74 | # else: 75 | # print("Have not met the DSA Criteria") 76 | # else: 77 | # print("Have not met the perentage Criteria") 78 | # else: 79 | # print("Invalid Degree") 80 | 81 | #Problem 3: print "Do Celebration" according to below criteria 82 | #isFriday=true, isClass=false, isAssignment=false 83 | 84 | # isFriday = True 85 | # isClass = False 86 | # isAssignment = False 87 | 88 | # if isFriday: 89 | # if isClass == False: 90 | # if isAssignment == False: 91 | # print("Do Celebration") 92 | # else: 93 | # print("There is assignment") 94 | # else: 95 | # print("Have Class") 96 | # else: 97 | # print("Not Friday") 98 | 99 | 100 | #Question: if you have 10 connected or dependent condtions then still you can write the solution but you will end with less readable and harder to maintain. 101 | 102 | # if isFriday: 103 | # if isClass == False: 104 | # if isAssignment == False: 105 | # print("Do Celebration") 106 | # if isAssignment == False: 107 | # print("Do Celebration") 108 | # if isAssignment == False: 109 | # print("Do Celebration") 110 | # if isAssignment == False: 111 | # print("Do Celebration") 112 | # else: 113 | # print("There is assignment") 114 | # else: 115 | # print("There is assignment") 116 | # else: 117 | # print("There is assignment") 118 | # else: 119 | # print("There is assignment") 120 | # else: 121 | # print("Have Class") 122 | # else: 123 | # print("Not Friday") 124 | 125 | #Solution is Logical Operator: 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 4/introductionToLoopExample.py: -------------------------------------------------------------------------------- 1 | #Why Loop: 2 | 3 | #If i ask you to print "Hello World" 10 times? 4 | print("Hello World") 5 | print("Hello World") 6 | print("Hello World") 7 | print("Hello World") 8 | print("Hello World") 9 | print("Hello World") 10 | print("Hello World") 11 | print("Hello World") 12 | print("Hello World") 13 | 14 | #What if i want you to print "Hello World" 1000 times? 15 | #Yes, you can print 1000 times as well but in this way your code will look less readable, lengthy and harder to maintain. 16 | #In this way your code will have duplicacy/Redundancy, which is not recommended as a developer. 17 | 18 | #What is the solution: Loop -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 4/moreAboutLogicalOperatorExample.py: -------------------------------------------------------------------------------- 1 | #Logical Operator: 2 | #1. Best Alternative of nested if else statmeent(once we have more than one dependent conditons) 3 | #2. it makes your code concise, easy to maintatin, and easy to understand. 4 | 5 | 6 | #There are following types of Logical Operators: 7 | #1. and logical operator 8 | #2. or logical operator 9 | #3. not logical operator 10 | 11 | 12 | #1. and logical operator: in the case of logical operator, if the all given conditions are true then entire expression will be true if any of the condition is false then entire expression will be false. 13 | 14 | #best for dependent conditions 15 | 16 | """ 17 | syntax: 18 | condition1 and condition2 and condition3 and condition4 19 | 20 | 21 | Case 1: 22 | conditon1 = True 23 | conditon2 = True 24 | conditon3 = True 25 | conditon4 = True 26 | 27 | result = condition1 and condition2 and condition3 and condition4 28 | result is True 29 | 30 | Case 2: 31 | conditon1 = False 32 | conditon2 = True 33 | conditon3 = True 34 | conditon4 = True 35 | 36 | result = condition1 and condition2 and condition3 and condition4 37 | result is False 38 | 39 | Case 3: 40 | conditon1 = False 41 | conditon2 = False 42 | conditon3 = True 43 | conditon4 = False 44 | 45 | result = condition1 and condition2 and condition3 and condition4 46 | result is False 47 | 48 | 49 | Table: 50 | 51 | A B C A and B and C 52 | True True True True and True and True : [True] 53 | True True False True and True and False :[False] 54 | True False False True and False and False :[False] 55 | False False False False and False and False :[False] 56 | 57 | Note: and opeartor always finds its next True, if anywhere it finds False entire expression will be False. 58 | """ 59 | 60 | 61 | #Example: Print Do marriege according to following criteria: 62 | #Gender: Male, Age>=21, graduate: True, isJob: True 63 | 64 | #Without Logical Operator: 65 | 66 | # gender = "male" 67 | # age = 23 68 | # isGraduate = True 69 | # isJob = True 70 | 71 | # if gender=="male": 72 | # if age>=21: 73 | # if isGraduate: 74 | # if isJob: 75 | # print("Do Marriege.") 76 | # else: 77 | # print("Sorry, You don't have job.") 78 | # else: 79 | # print("Sorry, do Graduation first.") 80 | # else: 81 | # print("Age is below 21") 82 | # else: 83 | # print("Gender is not matching.") 84 | 85 | #Above code is harder to maintain and dificult to understand then to make this code more readable and easy to maintain let's proceed with logical operator. 86 | #Logical and operator in above problem is the best choice. 87 | 88 | #Using logical and operator: 89 | 90 | # gender = "male" 91 | # age = 23 92 | # isGraduate = True 93 | # isJob = True 94 | 95 | # if gender == "male" and age>=21 and isGraduate and isJob: 96 | # print("Do Marriege") 97 | # else: 98 | # print("You're not eligiblle for marriege.") 99 | 100 | 101 | 102 | #Logical or Operator: In this case if among many conditions if any of the condition is true then entire expression will be True, if none of the condition is True then entire expresssion will be False. 103 | 104 | #best for independent conditions 105 | 106 | """ 107 | syntax: 108 | 109 | conditon1 or condition2 or condition3 or condition4 110 | 111 | Note: or operator it always finds its first True, if it doesn't find the True anywhere then it will make entire expression as False. 112 | 113 | Case 1: 114 | conditon1 = True 115 | conditon2 = True 116 | conditon3 = True 117 | conditon4 = True 118 | 119 | result = condition1 or condition2 or condition3 or condition4 120 | result is True 121 | 122 | Case 2: 123 | conditon1 = True 124 | conditon2 = False 125 | conditon3 = True 126 | conditon4 = False 127 | 128 | result = condition1 or condition2 or condition3 or condition4 129 | result is True 130 | 131 | Case 2: 132 | conditon1 = False 133 | conditon2 = False 134 | conditon3 = False 135 | conditon4 = False 136 | 137 | result = condition1 or condition2 or condition3 or condition4 138 | result is False 139 | 140 | 141 | Table: 142 | 143 | 144 | Table: 145 | 146 | A B C A or B or C 147 | True True True True or True or True : [True] 148 | True True False True or True or False :[True] 149 | True False False True or False or False :[True] 150 | False False False False or False or False :[False] 151 | 152 | """ 153 | 154 | 155 | #Example 1: check a letter is vowel or consonant: 156 | 157 | # letter = 'a' 158 | 159 | #Without Logial Operator: 160 | 161 | # if letter =='a': 162 | # print("Vowel") 163 | # elif letter == 'e': 164 | # print("Vowel") 165 | # elif letter == 'i': 166 | # print("Vowel") 167 | # elif letter == 'o': 168 | # print("Vowel") 169 | # elif letter == 'u': 170 | # print("Vowel") 171 | # else: 172 | # print("Consonant") 173 | 174 | 175 | #Logial or operator: 176 | 177 | # letter = 't' 178 | 179 | # if (letter == 'a') or (letter == 'e') or (letter == 'i') or (letter == 'o') or (letter == 'u'): 180 | # print("Vowel") 181 | # else: 182 | # print("Consonant") 183 | 184 | 185 | #Example: Print Do marriege according to following criteria: 186 | #Gender: Male, Age>=21, graduate: True, isJob: True 187 | #Gender: Female, Age>=21, graduate: True, isJob: True 188 | 189 | #Solution 190 | gender = "male" 191 | age = 23 192 | isGraduate = True 193 | isJob = True 194 | 195 | # if (gender == "male" and age>=21 and isGraduate and isJob) or (gender == "feamle" and age>=21 and isGraduate and isJob): 196 | # print("Do Marriege") 197 | # else: 198 | # print("You're not eligible") 199 | 200 | # if (gender == "male" or gender == "feamle") and age>=21 and isGraduate and isJob: 201 | # print("Do Marriege") 202 | # else: 203 | # print("You're not eligible") 204 | 205 | 206 | #Exmaple : print DO party if you have any of below condition: 207 | #isFriday: True 208 | #isRaining: True 209 | #isAssignment: False 210 | 211 | 212 | # isFriday = True 213 | # isRaining = False 214 | # isAssingment = False 215 | 216 | # if isFriday or isRaining or isAssingment==False: 217 | # print("Do Party") 218 | # else: 219 | # print("No Party") 220 | 221 | #3. not opeartor: it is used to negate the condtion value, if condition is True then this opeartor will make it false, if the value is True then this will make it False. 222 | 223 | """ 224 | syntax: 225 | not condition 226 | 227 | Note: not operator is used to negate the value. 228 | 229 | """ 230 | 231 | #Example 1: Print Do Party not day must not be Friday. 232 | 233 | # isFriday = False 234 | 235 | # if not isFriday: 236 | # print("Do Party") 237 | # else: 238 | # print("Not Party") 239 | 240 | #Exmaple : print DO party if you have any of below condition: 241 | #isFriday: True 242 | #isRaining: True 243 | #isAssignment: False 244 | 245 | # isFriday = False 246 | # isRaining = False 247 | # isAssingment = False 248 | 249 | # if isFriday or isRaining or not isAssingment: 250 | # print("Do Party") 251 | # else: 252 | # print("No Party") 253 | 254 | 255 | 256 | 257 | -------------------------------------------------------------------------------- /Unit 1/Sprint 3/Day 4/ternaryOperatorExample.py: -------------------------------------------------------------------------------- 1 | #Ternary Operator: it is used to use conditonal statement in concise manner or you can say it is the shorthand way of if else statement. 2 | 3 | """ 4 | syntax: 5 | 6 | [Print Statement if True] if condition else [Print Statement if False] 7 | 8 | Examples: 9 | 10 | age > = 18 - print "Eligible for vote." 11 | 12 | age = 23 13 | 14 | print("Eligible for Vote") if age>=21 else print("Not Eligible for vote") 15 | 16 | """ 17 | 18 | #Example: 19 | 20 | # age = 17 21 | 22 | #Case 1: 23 | # print("Eligible for Vote") if age>=21 else print("Not Eligible for vote") 24 | 25 | #Case 2: you can also return the statement. 26 | 27 | # result = "Eligible for Vote" if age>=21 else "Not Eligible for vote" 28 | # print(result) 29 | 30 | #More Concise way: 31 | 32 | # print("Eligible for Vote" if age>=21 else "Not Eligible for vote") 33 | 34 | 35 | #Example 2: Ternary Operator with Logical Operator: 36 | 37 | 38 | isFriday = False 39 | isRaining = False 40 | isAssingment = False 41 | 42 | # if isFriday or isRaining or not isAssingment: 43 | # print("Do Party") 44 | # else: 45 | # print("No Party") 46 | 47 | 48 | #Try above solution using ternary operator: 49 | # print("Do Party") if isFriday or isRaining or not isAssingment else print("No Party") 50 | 51 | # print("Do Party" if isFriday or isRaining or not isAssingment else "No Party") -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 1/notes.txt: -------------------------------------------------------------------------------- 1 | About for Loop -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 2/recapingLoopExample.py: -------------------------------------------------------------------------------- 1 | #Why Loop: 2 | 3 | #If i ask you to print "Hello World" 10 times? 4 | # print("Hello World") 5 | # print("Hello World") 6 | # print("Hello World") 7 | # print("Hello World") 8 | # print("Hello World") 9 | # print("Hello World") 10 | # print("Hello World") 11 | # print("Hello World") 12 | # print("Hello World") 13 | 14 | #What if i want you to print "Hello World" 1000 times? 15 | #Yes, you can print 1000 times as well but in this way your code will look less readable, lengthy and harder to maintain. 16 | #In this way your code will have duplicacy/Redundancy, which is not recommended as a developer. 17 | 18 | #What is the solution: Loop 19 | #Loop: It is an iterative statement which is used to execute/run block of code again and again. 20 | 21 | #There are following types of loop in python: 22 | #1. while loop: 23 | #2. for loop: 24 | 25 | #1. while loop: it is used to execute/run block of code again and again. 26 | """ 27 | syntax: 28 | 29 | startingPoint 30 | while condtion: 31 | #block of code 32 | #step: increment/decrement 33 | 34 | """ 35 | 36 | #Increment/Decrement: it is just a way to increase or decrease the value by some number. 37 | #Note: in python, increment and decrement operator is not supported but you can achieve this facility by using + and - operator. 38 | 39 | #Increment: 40 | 41 | # num = 10 42 | 43 | #increase the value of num by 1 44 | 45 | # num = num + 1 46 | # print(num) 47 | 48 | #increase the value of num by 10 49 | # num = num + 10 50 | # num = num+ 10 51 | # variable = value 52 | # print(num) # 21 53 | 54 | #Decrease the value of num by 10 55 | # num = num - 10 56 | 57 | # print(num) #11 58 | 59 | #Example 1: print hello world 10 times. 60 | 61 | #Note: loop only keeps on executing lines of code until the condition is true. 62 | 63 | # conditon = True 64 | 65 | # while conditon: 66 | # print("Hello World") 67 | 68 | #Procee of While loop Execution: check condition(True) --> block of code---> again check condtion(True) --> block of code--->check condtion(False)--->come out of the loop. 69 | 70 | #According to above condition, you while loop has become infinite loop as the condition is never gonna False. 71 | #What if we want to execute while for specific rounds, then need to take care about following part of loop: 72 | 73 | #1. startingPoint 74 | #2. where to stop (condition) 75 | #3. step 76 | 77 | # #Example 1: print hello world 5 times. 78 | # sp = 1 79 | # #condition = sp <= 5 80 | # while sp <= 5: 81 | # print("Hello World") 82 | # sp = sp + 1 83 | 84 | #Visualization/Dry Run for above loop 85 | """ 86 | 87 | 88 | Given: sp = 1 89 | Round 1: sp <= 5: True 90 | print "Hello World" 91 | sp = 1 + 1 => 2 92 | sp = 2 93 | Round 2: sp <= 5: True 94 | print "Hello World" 95 | sp = 2+1 => 3 96 | sp = 3 97 | Round 3: sp <= 5: True 98 | print "Hello World" 99 | sp = 3+1 => 4 100 | sp = 4 101 | Round 4: sp <= 5: True 102 | print "Hello World" 103 | sp = 4+1 => 5 104 | sp = 5 105 | Round 5: sp <= 5: True 106 | print "Hello World" 107 | sp = 5+1 => 6 108 | sp = 6 109 | Round 6: sp <= 5: False -> Come out of the loop 110 | 111 | """ 112 | 113 | #Example 2: print number from 1 to 10. 114 | # sp = 1 115 | 116 | # while sp <= 10: 117 | # print(sp) 118 | # sp = sp + 1 119 | 120 | #Example 3: print number from 10 to 1. 121 | # sp = 10 122 | 123 | # while sp >= 1: 124 | # print(sp) 125 | # sp = sp - 1 126 | 127 | #Example :4 print number from 1 to 10 but go 2 step at a time. 128 | 129 | # sp = 1 130 | 131 | # while sp <= 10: 132 | # print(sp) 133 | # sp = sp + 2 134 | 135 | #Good Example 1: print 10 natural numbers. 136 | 137 | # sp = 1 138 | 139 | # while sp <= 10: 140 | # print(sp) 141 | # sp = sp + 1 142 | 143 | #Good Example 1: print n natural numbers. 144 | 145 | # n = int(input("Enter the number: ")) 146 | # sp = 1 147 | 148 | # while sp <= n: 149 | # print(sp) 150 | # sp+= 1 # sp = sp + 1 151 | 152 | """ 153 | shorthand version of arithmetic operator: 154 | num = 1 155 | num = num + 1 ---> [num+= 1] 156 | num = num - 1 ---> [num-= 1] 157 | num = num * 1 ---> [num*= 1] 158 | num = num / 1 ---> [num/= 1] 159 | num = num // 1 ---> [num//= 1] 160 | num = num ** 1 ---> [num**= 1] 161 | """ 162 | 163 | #Good Example 2: to know how to use condional statement inside loop: 164 | #Problem Statment: print only even number from 1 to 10 165 | 166 | # sp = 1 167 | 168 | # while sp <= 10: 169 | # #create condtion to print only even number 170 | # if sp%2==0: 171 | # print(sp) 172 | # sp+=1 173 | 174 | #Problem Statment: print both even and odd number from 1 to 10 175 | 176 | # sp = 1 177 | 178 | # while sp<=10: 179 | # if sp%2==0: 180 | # print("Even Number", sp) 181 | # else: 182 | # print("Odd Number", sp) 183 | # sp+=1 184 | 185 | #Good Example 3: print multiple of 3 from 1 to 20 186 | 187 | # sp = 1 188 | 189 | # while sp <= 20: 190 | # if sp%3==0: 191 | # print(sp) 192 | # sp+=1 193 | # print(sp) #21 194 | 195 | #Good Example 4: find out the sum of first 5 natural numbers. 196 | 197 | sp = 1 198 | total = 0 199 | 200 | while sp <= 5: 201 | total+= sp 202 | sp+=1 203 | print(total) 204 | """ 205 | Visualization(Dry Run): 206 | Given = sp = 1, total = 0 207 | 208 | Round/Iteration 1: sp<=5: True 209 | total = 0 + 1 => 1 210 | [current total = 1] 211 | sp = 1 + 1 -> 2 212 | [current sp = 2] 213 | Round/Iteration 2: sp<=5: True 214 | total = 1 + 2 => 3 215 | [current total = 3] 216 | sp = 2 + 1 -> 3 217 | [current sp = 3] 218 | Round/Iteration 3: sp<=5: True 219 | total = 3 + 3 => 6 220 | [current total = 6] 221 | sp = 3 + 1 -> 4 222 | [current sp = 4] 223 | Round/Iteration 4: sp<=5: True 224 | total = 6 + 4 => 10 225 | [current total = 10] 226 | sp = 4 + 1 -> 5 227 | [current sp = 5] 228 | Round/Iteration 5: sp<=5: True 229 | total = 10 + 5 => 15 230 | [current total = 15] 231 | sp = 5 + 1 -> 6 232 | [current sp = 6] 233 | Round/Iteration 6 sp<=5: False --> Come out of the loop 234 | 235 | """ 236 | -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 3/breakAndContinueStatement.py: -------------------------------------------------------------------------------- 1 | #break statement: it is used to break/terminate/stop the running loop at certain condition. 2 | 3 | """ 4 | syntax 5 | while condition: 6 | if breakCondition: 7 | break 8 | # print(sp) 9 | increment/Decrement 10 | 11 | """ 12 | 13 | #Example: print from 1 to 10 but break at 6 14 | 15 | # sp = 1 16 | # while sp<=10: 17 | # if sp==6 or sp ==7: 18 | # break 19 | # print(sp) 20 | # sp+=1 21 | # """ 22 | # output: 23 | # 1 24 | # 2 25 | # 3 26 | # 4 27 | # 5 28 | # """ 29 | 30 | #Example: find out the first even number from 1 to 10 31 | 32 | # sp = 1 33 | # while sp<=10: 34 | # if sp%2==0: 35 | # print("Even", sp) 36 | # break 37 | # sp+=1 38 | 39 | 40 | #continue statement: it is used to terminate/stop/skip only particular iteration/round accoding to given condition. 41 | 42 | #Example 1: print number from 1 to 5 except 3 43 | 44 | # sp = 1 45 | 46 | # while sp<=5: 47 | # if sp==3: 48 | # continue 49 | # print(sp) 50 | # sp+=1 51 | 52 | """ 53 | above loop has become infinite loop because at sp value 3 you continue statement is terminating the current round because of this sp value has stucked at 3 54 | Visualization: 55 | Given: sp=1 56 | Round 1: sp<=5: True 57 | sp==3: False 58 | print: 1 59 | sp = 1 +1 =>2 60 | Round 2: sp<=5: True 61 | sp==3: False 62 | print: 2 63 | sp = 2 +1 =>3 64 | Round 3: sp<=5: True 65 | sp==3: True 66 | continue/terminate 67 | Round 4: sp<=5: True 68 | sp==3: True 69 | continue/terminate 70 | Round 5: sp<=5: True 71 | sp==3: True 72 | continue/terminate 73 | """ 74 | 75 | #What is the solution 76 | 77 | # sp = 0 78 | 79 | # while sp<=4: 80 | # sp+=1 81 | # if sp==3: 82 | # continue 83 | # print(sp) 84 | 85 | #Example: print 1 to 10 except 5 and 7 86 | 87 | sp = 0 88 | 89 | while sp<10: 90 | sp+=1 91 | if sp == 5 or sp ==7: 92 | continue 93 | print(sp) -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 3/forLoopExample.py: -------------------------------------------------------------------------------- 1 | #Why For Loop: As compare to while loop, for loop is the simple and consise in term of use that makes your code more readable and maintainable. 2 | 3 | #Problem with While loop: 4 | #1. in the case of while loop we're having to write following this at different place that increase the length/lines of code. 5 | #1. statingPoint 6 | #2. where to stop(condition) 7 | #3. step(increment/decrement) 8 | 9 | #Solution: your for loop solves the problem of while loop where you can write all three part of loop at one place using range() function 10 | 11 | #2. in the case of continue statement, it ends up with infinite loop, if you don't use continue statement in the right manner. 12 | 13 | #Solution: your for loop solves the problem of infinite loop and effectively use continue and break statement. 14 | 15 | #For Loop: it is also used to execute block of code/same lines of code again and again until the condition is true. 16 | 17 | """ 18 | syntax: 19 | 20 | for var_name in sequence: 21 | print("code to execute") 22 | 23 | Note: you can use range() to decite the sequence 24 | Example: 25 | 26 | Case 1: 27 | range(n) #n is integer number here 28 | #Example: 29 | for sp in range(5): 30 | print("code to execute") 31 | 32 | range(5) #sp=0, where to stop(sp<5), step=sp+=1 33 | 34 | Case 2: 35 | range(1, 5) 36 | #Example: 37 | for sp in range(1,5): 38 | print("code to execute") 39 | 40 | range(1,5) #sp=1, where to stop(sp<5), step=sp+=1 41 | 42 | Case 3: 43 | range(1, 5, 2) 44 | #Example: 45 | for sp in range(1,5,2): 46 | print("code to execute") 47 | 48 | range(1,5,2) #sp=1, where to stop(sp<5), step=sp+=2 49 | 50 | """ 51 | 52 | #Example 1: print number from 1 to 10 53 | 54 | # for sp in range(10): #sp = 0, sp<10, step=sp+=1 55 | # print(sp+1) 56 | 57 | # for sp in range(1,11): #sp = 1, sp<11, step=sp+=1 58 | # print(sp) 59 | 60 | # for sp in range(1,11,1): #sp = 1, sp<11, step=sp+=1 61 | # print(sp) 62 | 63 | #Example 2: print even number from 1 to 20 64 | #range(1, 21) 65 | 66 | # for sp in range(1,21): 67 | # if sp%2==0: 68 | # print(sp) 69 | 70 | #for loop execution process: 71 | #sp = 1---->check condition(true)-->for loop body execution --->increment of sp--->check condition(true)-->for loop body execution --->increment of sp--->check condition(false) -->come out fo the loop/for loop stopped. 72 | 73 | -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 3/moreAboutWhileLoopExample.py: -------------------------------------------------------------------------------- 1 | 2 | #Example 1: find out the sum of even number from 1 to 10 3 | 4 | # sum = 0 5 | # sp = 1 6 | 7 | # while sp <= 10: 8 | # if sp%2==0: 9 | # sum+=sp 10 | # sp+=1 11 | 12 | # print(sum) 13 | 14 | #Example 2: find out the product of even number from 1 to 10 15 | 16 | # sp = 1 17 | # product = 1 18 | 19 | # while sp <= 10: 20 | # if sp%2==0: 21 | # product+=sp 22 | # sp+=1 23 | 24 | # print(product) 25 | 26 | #Example 3: find out the factorial of given number. 27 | #5! - 5*4*3*2*1 28 | #6! - 6*5*4*3*2*1 29 | 30 | # num = 5 31 | # fact = 1 32 | # i= 1 33 | 34 | # while i<=num: 35 | # fact*=i 36 | # i+=1 37 | 38 | # print(fact) 39 | 40 | #Example: Write a program to check a given number is palindrome or not. 41 | #Palidrome Number: number Which looks same after reversing as well. 42 | #1221 <---> 1221 --1221 is a palindrome 43 | #Hint: %, //, / 44 | 45 | #Exmaple 4: print from 1 to 10 in one line. 46 | 47 | #Soluton 1: 48 | # sp =1 49 | # while sp <= 10: 50 | # print(sp, end=' ') # default value of end = '\n' 51 | # sp+=1 52 | 53 | #Soluton 2 54 | 55 | # bag = '' 56 | # sp = 1 57 | # while sp<=10: 58 | # bag+=str(sp)+" " 59 | # sp+=1 60 | 61 | # print(bag) 62 | 63 | -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 4/moreExamplesUsingForLoop.py: -------------------------------------------------------------------------------- 1 | #Example 1: find out factorial any number using for loop. 2 | 3 | # fact = 1 4 | # num = 5 5 | 6 | # for i in range(1, num+1): 7 | # fact*=i 8 | 9 | # print(fact) 10 | 11 | #Example 2: find out the sum of odd number from 1 to 50 12 | 13 | # total = 0 14 | 15 | # for i in range(1, 51): 16 | # if i%2!=0: 17 | # total+=i 18 | 19 | # print(total) 20 | 21 | #Exmaple 3: count the even number from 1 to 20 22 | 23 | # count = 0 24 | # for i in range(1,21): 25 | # if i%2==0: 26 | # count+=1 27 | 28 | # if count==0: 29 | # print("There is no even numeber") 30 | # else: 31 | # print("Even Numbers are:", count) 32 | 33 | 34 | 35 | # Example: check a number is prime or not. 36 | """ 37 | Visualization: 38 | Prime Number has two factors which means they can either divived by itself or 1 39 | 40 | Examples: 41 | 3---> 3%1----3/2----3/3 42 | Yes No Yes 43 | 1 1 44 | Note: If Factor count is exact 2 then you can say its prime number 45 | 46 | 4---> 4%1----4%2----4%3-----4%4 47 | Yes Yes No Yes 48 | 1 1 1 49 | Once there is 3 factors for 4 number that's why its not prime number. 50 | """ 51 | 52 | # num = 6 53 | # count = 0 54 | # for i in range(1, num + 1): 55 | # if num%i==0: 56 | # count+=1 57 | 58 | # if count==2: 59 | # print("Prime Number") 60 | # else: 61 | # print("Not Prime Number") 62 | -------------------------------------------------------------------------------- /Unit 1/Sprint 4/Day 4/nestedLoopExample.py: -------------------------------------------------------------------------------- 1 | #Nested Loop: Loop Within Loop 2 | #Other Words: When Any loop each iteration/round is related/connected to some set of rounds then in this condition you can achieve this using nested loop. 3 | 4 | """ 5 | Syntax: 6 | # outer loop 7 | for var1 in range(n): 8 | #inner loop 9 | for var2 in range(n): 10 | """ 11 | 12 | #Example: Gol Gappa Analogy: 13 | #20rs -- 4pcs 14 | 15 | # outer loop 16 | # for chintu in range(1, 5): 17 | # print(f"Chintu has done with his round {chintu}") 18 | # #inner loop 19 | # for family in range(1,5): 20 | # print(f"Family Member {family} has done with his round {chintu}") 21 | 22 | # using while loop 23 | # chintu=1 24 | # while chintu<=4: 25 | # print(f"Chintu has done with his round {chintu}") 26 | # #inner loop 27 | # family=1 28 | # while family<=5: 29 | # print(f"Family Member {family} has done with his round {chintu}") 30 | # family+=1 31 | # chintu+=1 32 | 33 | #Example 2: Father-Son Analogy 34 | #Problem Statement: Father will go for 2 rounds, in each round of father son will go for 5 rounds 35 | 36 | # outer loop 37 | # for father in range(1,3): 38 | # print(f"Father has started his round {father}") 39 | # # inner loop 40 | # for son in range(1, 6): 41 | # print(f"Son has done his round {son}") 42 | 43 | # print(f"Father has end his round {father}") 44 | 45 | #Using While loop 46 | # father = 1 47 | # while father<=2: 48 | # print(f"Father has started his round {father}") 49 | # # inner loop 50 | # son=1 51 | # while son<=5: 52 | # print(f"Son has done his round {son}") 53 | # son+=1 54 | # print(f"Father has end his round {father}") 55 | # father+=1 56 | 57 | #Student Task:Print in the blow manner: 58 | """ 59 | Father Round 1: Son Runds: 1 2 3 4 5 60 | Father Round 2: Son Runds: 1 2 3 4 5 61 | """ 62 | 63 | # for father in range(1,3): 64 | # print("Father Round:",father, end=' ') 65 | 66 | # print("Son Rounds:", end="") 67 | # for son in range(1, 6): 68 | # print(son, end=' ') 69 | # print() 70 | 71 | 72 | """ 73 | 1 2 3 4 5 74 | 1 2 3 4 5 75 | 1 2 3 4 5 76 | 1 2 3 4 5 77 | """ 78 | 79 | # for father in range(1,6): 80 | # for son in range(1,6): 81 | # print(son, end=' ') 82 | # print() 83 | 84 | """ 85 | 5 4 3 2 1 86 | 5 4 3 2 1 87 | 5 4 3 2 1 88 | 5 4 3 2 1 89 | """ 90 | 91 | # for father in range(1,6): 92 | # for son in range(5,0,-1): 93 | # print(son, end=' ') 94 | # print() 95 | 96 | """ 97 | * * * * * 98 | * * * * * 99 | * * * * * 100 | * * * * * 101 | """ 102 | 103 | # for father in range(1,6): 104 | # for son in range(5,0,-1): 105 | # print('*', end=' ') 106 | # print() 107 | 108 | """ 109 | 1 110 | 1 2 111 | 1 2 3 112 | 1 2 3 4 113 | 1 2 3 4 5 114 | """ 115 | 116 | # for father in range(1,6): 117 | # for son in range(1, father+1): 118 | # print(son, end=' ') 119 | # print() 120 | 121 | """ 122 | * 123 | * * 124 | * * * 125 | * * * * 126 | * * * * * 127 | """ 128 | 129 | # for father in range(1,6): 130 | # for son in range(1, father+1): 131 | # print('*', end=' ') 132 | # print() 133 | 134 | """ 135 | 1 2 3 4 5 136 | 1 2 3 4 137 | 1 2 3 138 | 1 2 139 | 1 140 | """ 141 | 142 | # for father in range(5,0,-1): 143 | # for son in range(1, father+1): 144 | # print(son, end=' ') 145 | # print() 146 | 147 | """ 148 | * * * * * 149 | * * * * 150 | * * * 151 | * * 152 | * 153 | """ 154 | 155 | for father in range(5,0,-1): 156 | for son in range(1, father+1): 157 | print('*', end=' ') 158 | print() 159 | 160 | #Conclusion: Outer loop is responsible for rows whereas inner loop is responsibel for column 161 | 162 | -------------------------------------------------------------------------------- /Unit 2/Sprint 1/Day 1/introductionPythonListExample.py: -------------------------------------------------------------------------------- 1 | #Note: Variable and List is a data structure - where data structure provide you some format/structure to store the data. 2 | 3 | #Why List? 4 | #-One limitation with Variable is that it can store one value at a time. 5 | 6 | #Example: store 10 interger numbers in variable. 7 | # num1= 10 8 | # num2 = 11 9 | # num3 = 12 10 | # num4 = 13 11 | # num5 = 14 12 | # num6 = 15 13 | # num7 = 16 14 | # num8 = 17 15 | # num9 = 18 16 | # num10 = 19 17 | 18 | #Note: Varibale is the best choice, you want to store less number of data of differnt type not same type. 19 | 20 | # name = "Rakesh" 21 | # age = 45 22 | # isMarried = True 23 | 24 | #Then If we want to store more data of same type then, Is there any solution? 25 | 26 | #Solution: List/Array - It is a data structure which is used to store multiple data of same type(Homogenous) or differnt type(Hatrogenous) in a single variable. 27 | 28 | #Declaration of List: 29 | 30 | # names = [] #declared/created a list with names 31 | # print(names) #empty list 32 | 33 | #Initialization of List 34 | #append(data): helps you to add/store the data to end of list. 35 | #Syntax: list_name.append(data) 36 | 37 | # Example 1: 38 | # names.append("Rakesh") #['Rakesh'] 39 | # names.append("Punit") #['Rakesh', 'Punit'] 40 | # names.append("Sunil") #['Rakesh', 'Punit', 'Sunil'] 41 | # names.append("Shubham") #['Rakesh', 'Punit','Sunil' ,'Shubham'] 42 | # names.append("Mahi") #['Rakesh', 'Punit','Sunil' ,'Shubham','Mahi'] 43 | # print(names) # ['Rakesh', 'Punit','Sunil' ,'Shubham','Mahi'] 44 | 45 | 46 | #Example 1: add 1 to 20 numbers in below list. 47 | 48 | # numbers = [] 49 | 50 | # for num in range(1,21): 51 | # numbers.append(num) 52 | 53 | # print(numbers) 54 | 55 | #Initialization at the time Declaration 56 | 57 | 58 | numbers = [1,2,3,4,5,6,7,8,9,10] 59 | 60 | """ 61 | How to access the element inside the list? 62 | Note: Python list follows 0 based indexing, meaning that first element in the list starts with 0 index, second element at index 1 and so on. 63 | Note: it also supports -ve indexing it means -1 index is for last element of the list and -2 or second last element of the list and so on. 64 | 65 | 66 | Example: 67 | 68 | nums = [1,2,3,4,5] 69 | index 0 1 2 3 4 70 | 71 | Note: to access any element of the list, it is important to know the index of that element. 72 | Syntax: list_name[index] 73 | 74 | print(nums[1]) 75 | print(nums[-4]) 76 | 77 | """ 78 | 79 | #Example 1: 80 | 81 | # nums = [1,2,3,4,5] 82 | # print(nums[1]) #2 83 | # print(nums[-4]) #2 84 | 85 | 86 | #Example 2: Given a list of fruits, your task is to print each fruit in seperate line. 87 | 88 | fruits = ["Papaya", "Mango", "Orange", "Kiwi", "Banana", "Apple", "Guava"] 89 | 90 | #First Way: 91 | 92 | # print(fruits[0]) 93 | # print(fruits[1]) 94 | # print(fruits[2]) 95 | # print(fruits[3]) 96 | # print(fruits[4]) 97 | # print(fruits[5]) 98 | # print(fruits[6]) 99 | 100 | #Second way: using loop: 101 | 102 | #1st Way: 103 | # for fruit in fruits: 104 | # print(fruit) 105 | 106 | #2nd Way: 107 | # for fruit in range(7): 108 | # print(fruits[fruit]) 109 | 110 | #Above range solution is static solution but as a developer, we need to create dynamic code so that due to any changes to the list, we could not change the loop code. 111 | 112 | #For this it is important to know how many elements are there in the list 113 | # count = 0 114 | # for fruit in fruits: 115 | # count+=1 116 | 117 | # print(f"number of element in the list:", count) 118 | 119 | # #Other Solution: len(list_name): helps to give you total number of elements in the list. 120 | 121 | # print(f"number of element in the list:", len(fruits)) 122 | 123 | # for fruit in range(len(fruits)): 124 | # print(fruits[fruit], end=' ') 125 | 126 | #Good Examlpe 1: Given a list of numbers, you need to print square of each number in one line. 127 | 128 | #input: nums = [1,2,3,4,5,6,7,8,9,10] 129 | #output: nums = [1,4,16,25,36,49,64,81,100] 130 | 131 | # nums = [1,2,3,4,5,6,7,8,9,10] 132 | 133 | # for number in range(len(nums)): 134 | # print(nums[number]**2, end=", ") 135 | 136 | #Good Examlpe 2: Given a list of numbers, you need to print even number in one line. 137 | 138 | # for number in range(len(nums)): 139 | # if nums[number]%2==0: 140 | # print(nums[number]**2, end=", ") 141 | 142 | #Good Examlpe 3: Given a list of numbers, you need to print odd number in one line. 143 | 144 | # for number in range(len(nums)): 145 | # if nums[number]%2!=0: 146 | # print(nums[number]**2, end=", ") 147 | 148 | #Good Examlpe 4: Given a list of numbers, you need to find odd number in the list and add to the new list. 149 | 150 | # nums = [1,2,3,4,5,6,7,8,9,10] 151 | # oddList = [] 152 | 153 | # for i in range(len(nums)): 154 | # if nums[i]%2!=0: 155 | # oddList.append(nums[i]) 156 | 157 | # print("Odd List:", oddList) 158 | 159 | #Good Examlpe 5: Given a list of numbers, you need to find even number in the list and add to the new list. 160 | 161 | # nums = [1,2,3,4,5,6,7,8,9,10] 162 | # evenList = [] 163 | 164 | # for i in range(len(nums)): 165 | # if nums[i]%2==0: 166 | # evenList.append(nums[i]) 167 | 168 | # print("Even List:", evenList) 169 | 170 | #Good Examlpe 6: Given a list of numbers, you need to find the factorial of even number and put them into a seperate list. 171 | 172 | nums = [1,2,3,4,5,6,7,8,9,10] 173 | 174 | #solution for factorial 175 | # num = 5 176 | # fact = 1 177 | # for n in range(1, num+1): 178 | # fact*=n 179 | # print(fact) 180 | 181 | # evenFactorialList = [] 182 | # for i in range(len(nums)): 183 | # if nums[i]%2==0: 184 | # fact = 1 185 | # for n in range(1, nums[i]+1): 186 | # fact*=n 187 | # evenFactorialList.append(fact) 188 | 189 | # print("Factorial Number List:",evenFactorialList) 190 | 191 | #Example 7: take input from user and add it to the list. 192 | 193 | # numberList = [] 194 | 195 | # num = int(input("Enter Numbers: ")) 196 | # numberList.append(num) 197 | 198 | # print("List: ", numberList) 199 | 200 | 201 | #Using loop: 202 | 203 | # numberList = [] 204 | 205 | # while True: 206 | # num = int(input("Enter Numbers: ")) 207 | # numberList.append(num) 208 | 209 | # res = input("Do you want to add more number(Y/N): ") 210 | # if res=='N' or res == 'n': 211 | # print(f"Current List: ", numberList) 212 | # break 213 | 214 | # nums = input("Enter Number space seperated: ") 215 | # print(nums) 216 | 217 | 218 | # numberList = [] 219 | 220 | #Example 1: 221 | 222 | numberList = [] 223 | 224 | #Taking input for the list. 225 | while True: 226 | num = int(input("Enter Numbers: ")) 227 | numberList.append(num) 228 | 229 | res = input("Do you want to add more number(Y/N): ") 230 | if res=='N' or res == 'n': 231 | print(f"Current List: ", numberList) 232 | break 233 | 234 | 235 | #Another Loop for performing following task on number list. 236 | #1. sum of all numbers 237 | #2. average of all numbers 238 | #3. list even numbers 239 | #4. list odd numbers 240 | #5. Exit 241 | 242 | while True: 243 | print("1. Sum of all Numbers") 244 | print("2. Average of all Numbers") 245 | print("3. List Even Numbers") 246 | print("4. List Odd Numbers") 247 | print("5. For Exit") 248 | choice = int(input("Enter Your Choice: ")) 249 | 250 | if choice==1: 251 | #logic for finding the sum 252 | sum = 0 253 | for num in numberList: 254 | sum+=num 255 | print("Sum of All Numbers: ",sum) 256 | elif choice==2: 257 | #logic for average 258 | sum = 0 259 | for num in numberList: 260 | sum+=num 261 | print("Average of All Number: ",sum/len(numberList)) 262 | elif choice==3: 263 | #logic for even number 264 | print("Even Numbers: ",end ='') 265 | for num in numberList: 266 | if num%2==0: 267 | print(num, end=' ') 268 | elif choice ==4: 269 | #logic for odd numebr 270 | print("Odd Numbers: ",end ='') 271 | for num in numberList: 272 | if num%2!=0: 273 | print(num, end=' ') 274 | elif choice==5: 275 | #logic for exit 276 | res = input("Do you want to Exit(Y/N): ") 277 | if res =='Y' or res =='y': 278 | print("Thank you for using!") 279 | break 280 | else: 281 | print("Invalid Input") -------------------------------------------------------------------------------- /Unit 2/Sprint 1/Day 1/moreAboutNestedLoopExample.py: -------------------------------------------------------------------------------- 1 | #Generate a multiplication table (1-10) for numbers 1 through 5 2 | 3 | # for table in range(1,6): 4 | # for number in range(1,11): 5 | # print(table,"*",number,"---",table*number) 6 | 7 | 8 | #Print all pairs of numbers (i, j) where 1 ≤ i, j ≤ 3. 9 | 10 | # for i in range(1, 3): 11 | # for j in range(1,4): 12 | # print(f"({i}, {j})", end=" ") 13 | # print() 14 | 15 | #Print a right-angled triangle of stars with 5 rows. 16 | 17 | """" 18 | * 19 | * * 20 | * * * 21 | * * * * 22 | * * * * * 23 | """ 24 | 25 | # for i in range(1,6): 26 | # for j in range(1, i+1): 27 | # print('*', end=' ') 28 | # print() 29 | 30 | """" 31 | ********** 32 | * * 33 | * * 34 | * * 35 | * * 36 | * * 37 | * * 38 | * * 39 | * * 40 | ********** 41 | """ 42 | 43 | # for row in range(1,11): 44 | # if (row==1 or row==10): 45 | # for star1 in range(1,11): 46 | # print('*',end='') 47 | # else: 48 | # for star2 in range(1,11): 49 | # if star2 == 1 or star2 == 10: 50 | # print('*', end='') 51 | # else: 52 | # print(' ', end='') 53 | # print() 54 | 55 | 56 | """ 57 | 1 58 | * 59 | 1 2 60 | * * 61 | 1 2 3 62 | * * * 63 | 1 2 3 4 64 | * * * * 65 | 1 2 3 4 5 66 | * * * * * 67 | """ 68 | 69 | # for i in range(1,6): 70 | # for j in range(1, i+1): 71 | # print(j, end=' ') 72 | # print() 73 | # for j in range(1, i+1): 74 | # print('*', end=' ') 75 | # print() 76 | 77 | """ 78 | * 79 | *** 80 | ***** 81 | ******* 82 | """ 83 | 84 | rows = 21 85 | 86 | for i in range(1,rows+1): 87 | # for space 88 | for space in range(rows-i): 89 | print(' ', end='') 90 | # for start 91 | for star in range(2*i-1): 92 | print('*', end='') 93 | print() 94 | 95 | """ 96 | * 97 | *** 98 | ***** 99 | *** 100 | * 101 | """ -------------------------------------------------------------------------------- /Unit 2/Sprint 1/Day 2/moreAboutListExample.py: -------------------------------------------------------------------------------- 1 | #Good Example 1: Given a list of numbers, you need find out square of even number and put them to the seperate list. 2 | 3 | # nums = [1,2,3,4,5,6,7,8,9,10] 4 | 5 | # evenSquareList = [] 6 | 7 | # for i in nums: 8 | # if i%2==0: 9 | # evenSquareList.append(i**2) 10 | 11 | # print(evenSquareList) 12 | 13 | #Good Example 2: Check a given list is empty list or not. 14 | 15 | # list1 = [] #List1 is empty 16 | 17 | # if len(list1)==0: 18 | # print("List1 is empty") 19 | # else: 20 | # print("List1 is not empty") 21 | 22 | # list2 = [3,4,5] #List2 is empty 23 | # if len(list2)==0: 24 | # print("List2 is empty") 25 | # else: 26 | # print("List2 is not empty") 27 | 28 | 29 | #Good Example 3: Given a list of numbers, you need to find out the minimum number and print it. 30 | 31 | # nums = [50,6,3,1,45,78,56,34,22] 32 | 33 | # minValue = nums[0] 34 | 35 | # for i in range(1,len(nums)): 36 | # if minValue > nums[i]: 37 | # minValue = nums[i] 38 | 39 | # print("Minimum Value is:",minValue) 40 | # #Can you find out the maximum value? 41 | 42 | #Important functions of list: 43 | # nums = [1,2,3,4,5,6,7,8,9,10] 44 | # total = sum(nums) 45 | 46 | # #Assignment: Try without using sum function 47 | # print(total) 48 | 49 | # minValue = min(nums) 50 | # #Assignment: Try without using sum function 51 | # print(minValue) 52 | 53 | # maxValue = max(nums) 54 | # #Assignment: Try without using sum function 55 | # print(maxValue) 56 | 57 | # size = len(nums) 58 | # #Assignment: Try without using sum function 59 | # print(size) 60 | 61 | #List Methods 62 | 63 | # nums = [4,12,34] 64 | 65 | # nums.append(45) #add element at the end of list 66 | # print(nums) # [4,12,34, 45] 67 | 68 | # nums.insert(2, 56) #[4,12,56,34 45] 69 | # print(nums) 70 | 71 | # nList = [90,100,120] 72 | 73 | # nums.extend(nList) 74 | # print(nums) 75 | 76 | # numbers = [1,2,3,4,5,6,7,8,9,10] 77 | 78 | # numbers.remove(5) 79 | # print(numbers) 80 | 81 | # fruits = ["Apple", "Banana", "Mango", "Grapes"] 82 | 83 | # fruits.remove("Mango") 84 | # print(fruits) #['Apple', 'Banana', 'Grapes'] 85 | 86 | #list.pop(): it removes element from end of the list, and it also returns removed element 87 | 88 | # removedElement = fruits.pop() 89 | # print(removedElement) #Grapes 90 | # print(fruits) 91 | 92 | #list.pop(index): it removes element at certain index and returned that removed element 93 | 94 | # fruits = ["Apple", "Banana", "Mango", "Grapes"] 95 | 96 | # removedElement = fruits.pop(0) 97 | # print(removedElement) 98 | # print(fruits) 99 | 100 | #list.reverse(): 101 | 102 | # nums = [1,2,3,4,5] 103 | # nums.reverse() 104 | # print(nums) 105 | 106 | 107 | #Conclusion list: 108 | """ 109 | 1. List is the best choice if your frequent operations are traversing/searching/visiting each element of the list. 110 | 111 | 2. List is the worst choice if your frequent operations are deleting and additing elements at sepecific element. 112 | 113 | Examples: 114 | 115 | nums = [1,2,3,4,5] 116 | 117 | Case 1: Addition 118 | add 6 at index 1 119 | In this case to add particular eleemnt, you're having to do lots of shifting which takes time that's why addition at some index is not the best choice. 120 | 121 | Case 2: Deletion 122 | nums = [1,2,3,4,5] 123 | delete element at index 3 124 | In this case to delete particular eleemnt, you're having to do lots of shifting which takes time that's why deletion of element at some index is not the best choice. 125 | 126 | 3. List is the best choice for same type(homogenous data) of data not for different type(hatrogenous) of data 127 | 128 | """ 129 | 130 | # names = ["Rakesh", "Chaman", "Deepak"] 131 | # ages = [45, 12, 23] 132 | # isMarried = [True, False, False] 133 | 134 | #Problem: print the age and married status of Rakesh 135 | 136 | # #Main Logic 137 | # for i in range(len(names)): 138 | # if names[i]=="Rakesh": 139 | # print("Ages of Rakesh: ", ages[i]) 140 | # print("Married Status of Rakesh: ","Married" if isMarried[i] else "Not Married") 141 | 142 | 143 | #Hatrogenous: 144 | 145 | # persons = ["Rakesh", 45, True, "Chaman", 12, False, "Deepak", 23, False] 146 | # #Problem: print the age and married status of Rakesh 147 | # #Extra Work: Filteration of data for putting the main logic 148 | # names =[] 149 | # for i in range(0,len(persons),3): 150 | # names.append(persons[i]) 151 | 152 | # ages =[] 153 | # for i in range(1,len(persons),3): 154 | # ages.append(persons[i]) 155 | 156 | # marriedStatus =[] 157 | # for i in range(2,len(persons),3): 158 | # marriedStatus.append(persons[i]) 159 | 160 | # print(names) 161 | # print(ages) 162 | # print(marriedStatus) 163 | 164 | # #Main Logic 165 | # for i in range(len(names)): 166 | # if names[i]=="Rakesh": 167 | # print("Ages of Rakesh: ", ages[i]) 168 | # print("Married Status of Rakesh: ","Married" if marriedStatus[i] else "Not Married") 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 1/introductionToFunctionExample.py: -------------------------------------------------------------------------------- 1 | #Function: It is a block of code related to specific functionality. 2 | 3 | #Why Function? 4 | 5 | # num1 = 5 6 | # count = 0 7 | # for i in range(1, num1+1): 8 | # if num1%i==0: 9 | # count+=1 10 | # if count==2: 11 | # print("Prime Numbers") 12 | # else: 13 | # print("Not Prime Number") 14 | 15 | # a, b = 45, 50 16 | # print(a+b) 17 | 18 | # value = input("Enter Value: ") 19 | # print("Enter Value is:", value) 20 | 21 | # c = 6 22 | # print(c**2) 23 | 24 | # num2 = 6 25 | # count = 0 26 | # for i in range(1, num2+1): 27 | # if num2%i==0: 28 | # count+=1 29 | # if count==2: 30 | # print("Prime Numbers") 31 | # else: 32 | # print("Not Prime Number") 33 | 34 | # result = 2**3 + 5//3 + 5 * 5 35 | # print(result) 36 | 37 | # num3 = 7 38 | 39 | # count = 0 40 | # for i in range(1, num3+1): 41 | # if num3%i==0: 42 | # count+=1 43 | # if count==2: 44 | # print("Prime Numbers") 45 | # else: 46 | # print("Not Prime Number") 47 | 48 | #Without using function, you're having to write duplicate code, there is no reusability but with the help of function we can reuse the code. 49 | 50 | 51 | #Declaration of Function: 52 | """ 53 | syntax: 54 | def functionName(): 55 | #function body 56 | """ 57 | 58 | #Declared function with name "add" 59 | # def add(): 60 | # num1 = 45 61 | # num2 = 15 62 | # print(num1 + num2) 63 | 64 | #How to use/call created function? - with helf of its name 65 | #syntax: functionName() 66 | #Calling the function means executing the function. 67 | 68 | 69 | # add() 70 | # add() 71 | # add() 72 | # add() 73 | # add() 74 | # add() 75 | 76 | #Example 2: 77 | 78 | #Declared three different function with name: playMusic(), stopMusic(), loopMusic() 79 | # def playMusic(): 80 | # print("Music started playing..") 81 | 82 | # def stopMusic(): 83 | # print("Music stopped playing..") 84 | 85 | # def loopMusic(): 86 | # print("Music started looping..") 87 | 88 | 89 | #calling created function: 90 | 91 | # playMusic() 92 | # loopMusic() 93 | # stopMusic() 94 | 95 | #Example 3: 96 | 97 | # def welcome(): 98 | # print("Welcome Rakesh! to Chitkara University") 99 | 100 | 101 | # welcome() 102 | # welcome() 103 | 104 | #Once above functions are static function therefore whenever you call these function they return whatever written inside their body. 105 | 106 | #How to create dynamic function - to create dynamic function you need to understand about function parameters and function arguments. 107 | 108 | #function parameters - they are just function variables that you take at the time function declaration. 109 | 110 | # def playMusic(music): 111 | # print(f"{music} started playing...") 112 | 113 | 114 | #calling the above function 115 | 116 | # music1 = "abc..." 117 | #Function Arguments: it is just a actual/original data/value that you're passing to the function at the time calling. 118 | 119 | # playMusic(music1) 120 | # playMusic("xyz...") 121 | 122 | 123 | def add(a, b): 124 | print(a+b) 125 | 126 | 127 | 128 | add(3,2) 129 | add(10,20) 130 | add(13,17) 131 | 132 | 133 | -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 1/slicingAndListComprehensionExample.py: -------------------------------------------------------------------------------- 1 | #Slicing In List: - It is used to slice/extract some part of your list in continuous manner and return that sliced/extracted list. 2 | 3 | """ 4 | Syntax: 5 | listName[sp:stop:step] - default values: sp = 0, stop: end of list, step:1 6 | 7 | nums = [1,2,3,4,5,6,7,8,9,10] 8 | 9 | nums[:] - [1,2,3,4,5,6,7,8,9,10] 10 | nums[1:] - [2,3,4,5,6,7,8,9,10] 11 | nums[1:3] - [2,3] 12 | nums[1::2] - [2,4,6,8,10] 13 | 14 | """ 15 | 16 | # nums = [1,2,3,4,5,6,7,8,9,10] 17 | 18 | # list1 = nums[:] 19 | # print(list1) #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 20 | 21 | # list2 = nums[2:] 22 | # print(list2) #[3, 4, 5, 6, 7, 8, 9, 10] 23 | 24 | # list2 = nums[2:5] 25 | # print(list2) #[3, 4, 5 ] 26 | 27 | # list3 = nums[::2] 28 | # print(list3) #[1, 3, 5, 7, 9] 29 | 30 | # nums = [1,2,3,4,5,6,7,8,9,10] 31 | 32 | # print(nums[-1:-5:-1]) 33 | 34 | # print(nums[-1::-1]) 35 | 36 | #List Comprehension: It is used to create the list and do some operation on list in short and concise manner. 37 | 38 | """ 39 | Syntax: 40 | list = [expression loop condition] 41 | 42 | Problem: Create a list of numbers from 1 to 10 43 | 44 | #Without LC 45 | nums = [] 46 | for i in range(1,11): 47 | nums.append(i) 48 | 49 | #With LC 50 | list = [x for x in range(1,11)] 51 | print(list) #[1,2,3,4,5,6,7,8,9,10] 52 | 53 | """ 54 | 55 | # list = [x for x in range(1,11)] 56 | # print(list) #[1,2,3,4,5,6,7,8,9,10] 57 | 58 | # list = [x**2 for x in range(1,11)] 59 | # print(list) # [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 60 | 61 | # list = [x**2 for x in range(1,11) if x%2==0] 62 | # print(list) # [4, 16, 36, 64, 100] 63 | 64 | 65 | nums = [23,34,45,56,67,89,34,12] 66 | 67 | # list = [x for x in nums if x%2==0] 68 | # print(list) -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 2/aboutpasskeywordExample.py: -------------------------------------------------------------------------------- 1 | #pass: whenever you don't have any code under any block in python then it will give indentation error if you don't want such kind of situation then you can use pass keyword which is nothing but absence of code 2 | 3 | #pass - absence of code 4 | 5 | 6 | #conditonal statement 7 | 8 | if 4==4: 9 | pass #absence of code 10 | 11 | 12 | name = "Rakesh" 13 | 14 | for i in range(1,11): 15 | pass 16 | 17 | num = 45 18 | 19 | def welcome(): 20 | pass -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 2/moreAboutFunctionExample.py: -------------------------------------------------------------------------------- 1 | #Passing Arguments 2 | 3 | #Example 1: Create a function that take two parameters of number type and print the diffrerence of those number. 4 | 5 | # def findDifference(num1,num2): 6 | # print(num1-num2) 7 | 8 | 9 | # #Positional Arguments 10 | # findDifference(34, 20) 11 | # findDifference(56, 78,78) #TypeError: findDifference() takes 2 positional arguments but 3 were given 12 | 13 | 14 | #Example 2: Create a function that accept a list of numbers and find out the sum of all the numbers 15 | 16 | 17 | # def sumOfNumberListElement(numList): 18 | # sum = 0 19 | # for i in numList: 20 | # sum+=i 21 | # print(f"Sum of Numbers - {sum}") 22 | 23 | 24 | # #Arguments 25 | # numList = [1,2,3,4,5,6,7,8,9,10] 26 | # sumOfNumberListElement(numList) #First Call with [1,2,3,4,5,6,7,8,9,10] arguments 27 | 28 | # sumOfNumberListElement([45, -45, -3]) # Second Call with [45, -45, -3] arguments 29 | 30 | #Student Task: 31 | 32 | # def anyFun(): 33 | # print("Nothing is here") 34 | 35 | # anyFun() 36 | 37 | 38 | # def printABoutYou(name="No Name Found", age="Not yet born", city="No City Found"): 39 | # print(f"Your Name {name}") 40 | # print(f"Your Age {age}") 41 | # print(f"Your City {city}") 42 | 43 | 44 | # #Default Arguments 45 | # printABoutYou("Rakesh", 45, "Noida") 46 | # print("-------------------------------") 47 | # printABoutYou("Rakesh", 45) 48 | # print("-------------------------------") 49 | # printABoutYou() 50 | 51 | 52 | # def printABoutYou(name, age): 53 | # print(f"Your Name {name}") 54 | # print(f"Your Age {age}") 55 | 56 | # printABoutYou("Rakesh", 56) 57 | # print("------------------------------------") 58 | # # printABoutYou(56, "Rakesh") 59 | # #Solution for second call 60 | # #Keyword Arguments 61 | # printABoutYou(age = 56, name = "Rakesh") 62 | 63 | 64 | #Arbitrary Arguments: *varible_name - it returns tuple 65 | #sum(iterator) - iterator - list/tuple 66 | 67 | # def findSum(a,b,c,d,e,f,g,h,i): 68 | # print(a+b+c+d+e+f+g+h+i) 69 | 70 | # findSum(1,2,3,4,5,6,7,8,9) 71 | 72 | #In below both of the case it will give error 73 | # findSum(1,2,3,4,5) 74 | # findSum(1,2,3,4,5,56,34,23,34,5,67,78,89,45,34,23,56) 75 | 76 | # def findSum(*numbers): 77 | # # print(arwt) 78 | # print(sum(numbers)) 79 | 80 | # #Arbitrary Arguments: 81 | # findSum(1,2,3,4,5,56,34,23,34,5,67,78,89,45,34,23,56) 82 | 83 | """ 84 | Student Tasks: 85 | 86 | Task 1: 87 | Write a function introduce_person(name, age, city) that prints a sentence introducing a person. 88 | Call the function using positional arguments and keyword arguments in different orders. 89 | 90 | Task 2: 91 | 92 | Write a function greet_person(name, greeting="Hello") that prints a greeting. 93 | Call the function with: 94 | Only the name argument. 95 | Both name and greeting arguments. 96 | 97 | Task 3: 98 | 99 | Write a function sum_numbers(*args) that accepts any number of arguments and returns their sum. 100 | Call the function with different numbers of arguments. 101 | 102 | """ 103 | 104 | 105 | #Note: 106 | 107 | # def isEven(num): 108 | # if num%2==0: 109 | # print("Even") 110 | # else: 111 | # print("Odd") 112 | 113 | # isEven(45) 114 | # isEven(11) 115 | # isEven(67) 116 | # isEven(34) 117 | 118 | 119 | 120 | #According to above examples, your functions are printing the result immeditely, what if you don't want your function to print result immeditely, you just want your function to return the result so that whenever you need to print/use the result, you can use it. 121 | 122 | #How will you do the above facility using function? 123 | #using return keyword 124 | 125 | #Note: using return keyword, your function can also return something. 126 | 127 | """ 128 | syntax: 129 | return expression 130 | """ 131 | 132 | #Example 1: 133 | 134 | # def isEven(num): 135 | # if num%2==0: 136 | # return "Even" 137 | # else: 138 | # return "Odd" 139 | 140 | # result = isEven(45) 141 | # # Odd 142 | # print(result) 143 | 144 | # print("-------------------") 145 | # print(isEven(56)) 146 | 147 | 148 | #Problem: given below expression, your task is to find out the product of given expression 149 | 150 | #exp1 = 45 + 56 151 | #exp2 = 56 - 10 152 | 153 | #output = exp1 * exp2 154 | 155 | def sum(a,b): 156 | return a+b 157 | 158 | def difference(a,b): 159 | return a-b 160 | 161 | def product(a,b): 162 | return a*b 163 | 164 | exp1 = sum(45, 56) 165 | exp2 = difference(56, 10) 166 | result = product(exp1, exp2) 167 | print(result) 168 | 169 | #shorthand way 170 | 171 | print(product(sum(45, 56),difference(56, 10))) -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 3/breakVsReturnExample.py: -------------------------------------------------------------------------------- 1 | #1. return is like big bom whereas berak is like a small bom. 2 | 3 | def printEvenNumbersFromList(nums): 4 | print("Starting of For Loop") 5 | for i in nums: 6 | if i%2==0: 7 | print(i) 8 | break 9 | # return i 10 | print("Ending of For Loop") 11 | 12 | # print(printEvenNumbersFromList([1,2,3,4,5,6,7,8])) 13 | printEvenNumbersFromList([1,2,3,4,5,6,7,8]) 14 | 15 | #2. return able to retun some expression whereas break can't do this. -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 3/iteratorExample.py: -------------------------------------------------------------------------------- 1 | #Iterator: it is object which is used to traverse through sequence/collection(iterable) one by one. 2 | 3 | list = [1,2,3,4,5,6] 4 | 5 | numbers = iter(list) 6 | 7 | # value = next(numbers) 8 | # print(value) #1 9 | # print(next(numbers)) #1 10 | # print(next(numbers)) #2 11 | # print(next(numbers)) #3 12 | # print(next(numbers)) #4 13 | # print(next(numbers)) #5 14 | # print(next(numbers)) #6 15 | 16 | #Iterator in 'for' loop 17 | 18 | for i in list: 19 | print(i, end=" ") 20 | 21 | for i in range(len(list)): 22 | print(list[i], end=" ") -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 3/moreAboutFunctionExample.py: -------------------------------------------------------------------------------- 1 | """ 2 | There are two types of function in python: 3 | 1. User Defined/Custom Function: You can create function according to your requirement. 4 | 2. Inbuilt/Pre-Defined Function: Some functions are already there in python library rather than creating the sepereate function for the same functionality its better to use them. 5 | """ 6 | 7 | #User-Defined Function: 8 | # def findListLength(list): 9 | # count = 0 10 | # for i in list: 11 | # count+=1 12 | # return count 13 | 14 | # print(findListLength([1,2,3,4,5])) 15 | # print(findListLength(["Rakesh", "Deepak", "Sunil", "Pawan"])) 16 | 17 | # #Python Inbuilt Function: 18 | # len(iterable) 19 | # print(len([1,2,3,4,5])) 20 | # print(len(["Rakesh", "Deepak", "Sunil", "Pawan"])) 21 | 22 | #sum(iterable): it supports only number type iterable 23 | # print(sum([1,2,3,4,5])) 24 | 25 | #id() 26 | # name1 = "Suresh" 27 | # name2 = "Suresh" 28 | # print(id(name1)) 29 | # print(id(name2)) 30 | 31 | # print(abs(-23)) 32 | # print(abs(-23+10)) 33 | # print(abs(-23.45)) 34 | 35 | #List Methods 36 | #append(), copy(), insert(), remove(element), pop(), pop(index), extend(), reverse(), index(element) 37 | 38 | # names = ["Chunnu", "Pintu", "Chintu", "Bablu", "Munnu"] 39 | # names.append("Chaman") 40 | # #print(names) 41 | 42 | # #insert(index, data) 43 | 44 | # names.insert(1, "Rinku") 45 | # print(names) 46 | 47 | # #remove(element): it removes particular element from the list. 48 | # # names.remove("Rinku") 49 | # # print(names) 50 | 51 | # #pop(): it removes the element at the end of the list and returns that removed element. 52 | 53 | # removedElement = names.pop() 54 | # #print(removedElement) 55 | # print(names) #['Chunnu', 'Rinku', 'Pintu', 'Chintu', 'Bablu', 'Munnu'] 56 | 57 | # #pop(index): it removes particular element from specific index and returns that removed element: 58 | # removedElement = names.pop(2) 59 | # print(removedElement) 60 | # print(names) #['Chunnu', 'Rinku', 'Chintu', 'Bablu', 'Munnu'] 61 | 62 | # #extends(): it extends the particular list- it merges the elements from another list. 63 | # engineersNames = ["Rakesh", "Suresh"] 64 | # names.extend(engineersNames) 65 | # print(names) #['Chunnu', 'Rinku', 'Chintu', 'Bablu', 'Munnu', 'Rakesh', 'Suresh'] 66 | 67 | # names.reverse() 68 | # print(names) #['Suresh', 'Rakesh', 'Munnu', 'Bablu', 'Chintu', 'Rinku', 'Chunnu'] 69 | 70 | # #count(element): it returns the count of occurance for particular element in the list. 71 | # names.append("Rakesh") 72 | # print(names.count("Rakesh")) 73 | 74 | # #index(element): it returns the index for particular element in the list.\\ 75 | 76 | # print(names.index("Suresh")) 77 | 78 | 79 | #Other Methods: 80 | 81 | import math 82 | 83 | # print(math.factorial(5)) #120 84 | 85 | # print(math.ceil(4.5)) #5 86 | # print(math.ceil(4.4)) #5 87 | # print(math.ceil(4.7)) #5 88 | # print(math.ceil(4.2)) #5 89 | 90 | # print(math.floor(4.5)) #4 91 | # print(math.floor(4.4)) #4 92 | # print(math.floor(4.7)) #4 93 | # print(math.floor(4.2)) #4 94 | 95 | # print(math.gcd(2,10)) 96 | # print(math.lcm(2,10)) 97 | #2 - 2*1 98 | #10 - 5*2*1 99 | 100 | import random 101 | 102 | # print(random.random()) # generates randome number between 0 and 1 103 | 104 | #fix the range for generating random number 105 | # print(random.randint(1, 20)) 106 | 107 | 108 | #random method for list. 109 | # print(random.choice(["Apple", "Banana", "Mango", "Grapes"])) 110 | 111 | # fruits = ["Apple", "Banana", "Mango", "Grapes"] 112 | # random.shuffle(fruits) 113 | 114 | # print(fruits) 115 | -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 3/yieldStatementAndGeneratorFunctionExample.py: -------------------------------------------------------------------------------- 1 | #yield statement: Unlike return, yeild keyword remebers the previous and in each execution it stops the function returns the value and again resumes the function returns the value and so on. 2 | 3 | #such functions are known as generator function, and these function return iterator. 4 | 5 | # def printEvenNumbersFromList(nums): 6 | # for i in nums: 7 | # if i%2==0: 8 | # yield i 9 | 10 | 11 | # nums = [1,2,3,4,5,6,7,8,9,10] 12 | # value = printEvenNumbersFromList(nums) 13 | 14 | # for i in value: 15 | # print(i, end=" ") 16 | 17 | # for i in printEvenNumbersFromList(nums): 18 | # print(i, end=" ") -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 4/introductionToRecursiveFunctionExample.py: -------------------------------------------------------------------------------- 1 | #Recursion: It is just a technique which is used to break down complex problem into smaller sub-problems.and 2 | 3 | 4 | #To Use Recursion in your code, you need to understand about two imporant parts of Recursion: 5 | #1. Recursive Function: It is like a function which call itself during the its execution, if your function keeps on calling itself again and again then it will end up with infinite call. 6 | #2. Base Condition: It is used to stop/termiate the recursive function 7 | 8 | """ 9 | syntax: 10 | 11 | #declartion of function 12 | def add(): 13 | if baseCondition: 14 | #stop 15 | add() 16 | 17 | 18 | #calling the function 19 | add() 20 | """ 21 | 22 | #Example 1: Find out the factorial of given number. 23 | 24 | #Using Tranditional Approach 25 | # num = 5 26 | # fact = 1 27 | 28 | # for i in range(1, num+1): 29 | # fact*=i 30 | # print(fact) 31 | 32 | #Recursive Approach - using Recursion 33 | 34 | # def factorial(num): 35 | # if num==1: 36 | # return 1 37 | # return num * factorial(num-1) 38 | 39 | # print(factorial(10)) 40 | 41 | #Example 2: Define a function sum_of_natural_numbers(n) that returns the sum of the first n natural numbers. 42 | 43 | #Without Recursion 44 | 45 | # def sumOfNaturalNumber(nums): 46 | # sum = 0 47 | # for i in range(1, nums+1): 48 | # sum+=i 49 | # return sum 50 | 51 | # print(sumOfNaturalNumber(10)) 52 | 53 | #Recusrion? 54 | 55 | # def sum_of_n_natural_numbers(n): 56 | # if n==1: 57 | # return 1 58 | # return n + sum_of_n_natural_numbers(n-1) 59 | 60 | # print(sum_of_n_natural_numbers(10)) 61 | 62 | 63 | #Example 3: Print list of numbers using recursion 64 | names = ["Rakesh", "Deepak", "Suresh", "Pankaj", "Rishi", "Rohan"] 65 | 66 | def printListElement(nameList, index): 67 | if index >= len(nameList): 68 | return 69 | # print(nameList[index]) 70 | yield nameList[index] 71 | printListElement(nameList, index+1) 72 | 73 | for i in printListElement(names, 0): 74 | print(i, end=" ") 75 | 76 | 77 | """ 78 | Task 6: 79 | Write a recursive function that takes a string and returns its reverse. 80 | 81 | Task 7: 82 | Count the Number of Digits in a Number 83 | 84 | Task 8: 85 | Sum of Digits of a Number 86 | """ 87 | -------------------------------------------------------------------------------- /Unit 2/Sprint 2/Day 4/lambdaFunctionExample.py: -------------------------------------------------------------------------------- 1 | #Lambda Function: It is an annoymous funciton(a function without name) which is used to write the function in short and concise manner. 2 | 3 | """ 4 | syntax: 5 | variableName = lambda parameters : exprssion/body 6 | 7 | #Normal Function 8 | 9 | def welcome(name) 10 | print(f"Welcome {name}") 11 | 12 | welcome("Rakesh") 13 | 14 | #Convert above function to lambda function 15 | welcomeFunc = lambda name : print(f"Welcome {name}") 16 | welcomeFunc("Rakesh") 17 | 18 | """ 19 | 20 | #Example 1: 21 | #Normal Function 22 | 23 | # def welcome(name): 24 | # print(f"Welcome {name}") 25 | 26 | # welcome("Rakesh") 27 | 28 | # #Convert above function to lambda function 29 | 30 | # welcomeFunc = lambda name : print(f"Welcome {name}") 31 | # welcomeFunc("Rakesh") 32 | 33 | # #Example 2: 34 | 35 | # def add(a,b): 36 | # return a+b 37 | 38 | # print(add(2,3)) 39 | 40 | # #Convert to lambda funciton 41 | # addFun = lambda a,b: a+b 42 | # print(addFun(2,3)) 43 | 44 | # #Example 3: 45 | 46 | # def findEvenList(nums): 47 | # evenList = [] 48 | # for i in nums: 49 | # if i%2==0: 50 | # evenList.append(i) 51 | # return evenList 52 | 53 | # print(findEvenList([1,2,3,4,5,6,7,8,9,10])) 54 | 55 | # #Let's convert above function into lambda function 56 | 57 | # findEvenListFun = lambda nums : [x for x in nums if x%2==0] 58 | 59 | # print(findEvenListFun([1,2,3,4,5,6,7,8,9,10])) 60 | 61 | 62 | """ 63 | Conclusion about Lambda Funciton: 64 | 1. It is single line function meaning that it supports single line the body. 65 | 2. for printing any expression, you don't need to write return keyword 66 | 3. for taking many paramerters, you can define parameters comma seperated. 67 | """ 68 | 69 | #Example 1: check a number is even or odd using lambda function. 70 | 71 | # isEven = lambda num: num%2==0 72 | # print(isEven(20)) 73 | # print(isEven(21)) 74 | 75 | # isEven = lambda num: "Even" if num%2==0 else "Odd" 76 | # print(isEven(20)) 77 | # print(isEven(21)) 78 | 79 | #Example 2: print even number in one line from 1 to 10 -------------------------------------------------------------------------------- /Unit 2/Sprint 3/Day 1/notes.txt: -------------------------------------------------------------------------------- 1 | Revision of ST-1 -------------------------------------------------------------------------------- /Unit 2/Sprint 3/Day 2/introductionTo2DList.py: -------------------------------------------------------------------------------- 1 | #1D List: it is just is collection of elements shared as a single variable. 2 | 3 | nums = [1,2,3,4,5,6,7,8,9,10] 4 | 5 | #2D List: it is also collections of elements in the form of matrix which is also shared as a single variable. 6 | 7 | nums = [[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15]] 8 | 9 | #Example 1: Create a list which is having string, numbers, and another list. 10 | 11 | student = ["Chintu", 34, True, ["Java", "Javascript", "Python", "React"]] 12 | 13 | #Why 2D List? - if you want to store the data in the form of rows and column then 2D List is the best choice. 14 | #It is just collection of inner lists. 15 | 16 | 17 | #Declaration of list 18 | 19 | # nums = [ 20 | # [1,2,3,4,5], 21 | # [6,7,8,9,10], 22 | # [11,12,13,14,15] 23 | # ] 24 | 25 | #to access particular element in the 2D List - listName[row][column] 26 | #Example 27 | # print(nums[0][2]) 28 | # print(nums[1][4]) 29 | # print(nums[2][3]) 30 | 31 | #replacement/updatino: 32 | 33 | # nums[2][3] = 20 34 | # print(nums) 35 | 36 | # nums = [] 37 | # # nums.append([1,2,3,4,5]) 38 | # # print(nums) 39 | # bag = [] 40 | # for i in range(1, 16): 41 | # if (i==5) or (i==10) or (i==15): 42 | # bag.append(i) 43 | # nums.append(bag) 44 | # bag = [] 45 | # bag.append(i) 46 | 47 | # print(nums) 48 | 49 | #To access element through loop, two things are important: rows and columns. 50 | 51 | #Consistent columns. 52 | # nums = [ 53 | # [1,2,3,4,5], 54 | # [6,7,8,9,10], 55 | # [11,12,13,14,15] 56 | # ] 57 | 58 | #Rows 59 | # print(len(nums)) #3 60 | # #Columns 61 | # print(len(nums[0])) #5 62 | 63 | #Not Consistent columns. 64 | # nums = [ 65 | # [1,2,3,4,5], 66 | # [6,7,8], 67 | # [11,12,13,15] 68 | # ] 69 | 70 | #Rows 71 | # print(len(nums)) #3 72 | #Columns 73 | #Note: in the above case, you will have to select each rows for exact column size. 74 | 75 | # print(len(nums[0])) 76 | # print(len(nums[1])) 77 | # print(len(nums[2])) 78 | 79 | 80 | #Consistent Column Example 81 | # nums = [ 82 | # [1,2,3,4,5], 83 | # [6,7,8,9,10], 84 | # [11,12,13,14,15] 85 | # ] 86 | 87 | # rows = len(nums) 88 | # columns = len(nums[0]) 89 | 90 | # #outer loop: rows 91 | # for row in range(0, rows): 92 | # #inner loop: columns 93 | # for column in range(0,columns): 94 | # print(nums[row][column], end=" ") 95 | # print() 96 | 97 | #Different Column Size: 98 | nums = [ 99 | [1,2,3,4,5], 100 | [6,7,8], 101 | [11,12,13,15] 102 | ] 103 | 104 | rows = len(nums) 105 | 106 | #outer loop: rows 107 | for row in range(0, rows): 108 | #inner loop: columns 109 | for column in range(0,len(nums[row])): 110 | print(nums[row][column], end=" ") 111 | print() 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Unit 2/Sprint 3/Day 3/notes.txt: -------------------------------------------------------------------------------- 1 | Pankaj sir revised the 2D List. -------------------------------------------------------------------------------- /Unit 2/Sprint 3/Day 4/moreAbout2DListExample.py: -------------------------------------------------------------------------------- 1 | items=[ 2 | ["Ajay", 28, "male", [1,2,3]], 3 | ["Hitesh", 30, "male", [4,5,6]] 4 | ]; 5 | 6 | #Want to access 3 7 | print(items[0][3][2]) 8 | print(items[1][2][1]) 9 | print(items[1][0][2]) 10 | 11 | 12 | #Student Tasks: 13 | 14 | #Problem 1: 15 | 16 | # items=[ 17 | # [1,2,3], 18 | # [4,5,6], 19 | # [7,8,9] 20 | # ]; 21 | 22 | # rows = len(items) 23 | # columns = len(items[1]) 24 | 25 | # #outer loop: rows 26 | # for row in range(rows): 27 | # #inner loop: columns 28 | # for column in range(columns): 29 | # print(items[row][column], end=" ") 30 | # print() 31 | 32 | 33 | #Problem 2 34 | # items=[ 35 | # [1,2,3], 36 | # [4,5,6], 37 | # [7,8,9,56,34], 38 | # [2,3,4,6,7,8,10] 39 | # ]; 40 | 41 | # rows = len(items) 42 | 43 | # #outer loop: rows 44 | # for row in range(rows): 45 | # #inner loop: columns 46 | # for column in range(len(items[row])): 47 | # print(items[row][column], end=" ") 48 | # print() 49 | 50 | #Problem 3: print row wise sum of the following 2D List. 51 | 52 | #input 53 | items=[ 54 | [1,2,3], 55 | [4,5,6], 56 | [1,8,9] 57 | ]; 58 | 59 | #output 60 | 6 61 | 15 62 | 24 63 | 64 | #outer loop: rows 65 | # for row in range(len(items)): 66 | # #inner loop: columns 67 | # sum = 0 68 | # for column in range(len(items[0])): 69 | # sum+=items[row][column] 70 | # print(sum) 71 | 72 | #Problem 4: print even sum row wise. 73 | 74 | #outer loop: rows 75 | # for row in range(len(items)): 76 | # #inner loop: columns 77 | # sum = 0 78 | # for column in range(len(items[0])): 79 | # if items[row][column]%2==0: 80 | # sum+=items[row][column] 81 | # print(sum) 82 | 83 | #Problem 5: print yes if there is atleast one prime number in row if not then print no, do this for all rows 84 | 85 | def checkPrime(num): 86 | count=0 87 | for i in range(1, num+1): 88 | if num%i==0: 89 | count+=1 90 | return count==2 91 | 92 | 93 | for row in range(len(items)): 94 | #inner loop: columns 95 | noticePerson = False 96 | for column in range(len(items[0])): 97 | if checkPrime(items[row][column]): 98 | noticePerson=True 99 | break 100 | if noticePerson: 101 | print("Yes") 102 | else: 103 | print("No") 104 | 105 | 106 | #Problem 6: Do above operation column wise. 107 | 108 | -------------------------------------------------------------------------------- /Unit 2/Sprint 4/Day 1/2DListExamples.py: -------------------------------------------------------------------------------- 1 | # #Below is the jagged list 2 | # nums = [ 3 | # [1,2,3], 4 | # [4,5], 5 | # [6,7,8,9,10] 6 | # ] 7 | 8 | # for i in range(len(nums)): 9 | # for j in range(len(nums[i])): 10 | # print(nums[i][j], end=" ") 11 | # print() 12 | 13 | # nums = [ 14 | # [1,2,3,5,4], 15 | # [4,5,5,3,5], 16 | # [6,7,8,9,10] 17 | # ] 18 | 19 | # for i in range(len(nums)): 20 | # for j in range(len(nums[0])): 21 | # print(nums[i][j], end=" ") 22 | # print() 23 | 24 | #Example 1: Given a list below, your task is to perform following Operations. 25 | 26 | # nums = [ 27 | # [1,2,3,4], 28 | # [4,5,6,4], 29 | # [7,8,9,6], 30 | # [7,8,9,10], 31 | # ] 32 | 33 | # """ 34 | # Visualization: 35 | # 1(nums[0][0]) + 5(nums[1][1]) + 9(nums[2][2]) 36 | 37 | # for i in range(len(nums)): 38 | # print(nums[i][i], end=" ") 39 | 40 | # 4(nums[0][3]) + 6(nums[1][2]) + 8(nums[2][1]) + 7(nums[3][0]) 41 | 42 | # for i in range(len(nums)): 43 | # print(nums[i][len(nums)-1-i], end=" ") 44 | # """ 45 | 46 | 47 | # #Example 2: 48 | 49 | # # nums = [ 50 | # # [1,2,3,4], 51 | # # [4,5,6,4], 52 | # # [7,8,9,6], 53 | # # [7,8,9,10], 54 | # # ] 55 | 56 | # """ 57 | # 1(nums[0][0]) 2(nums[0][1]) 3(nums[0][2]) 4(nums[0][3])-- 58 | # 4(nums[1][3]) 6(nums[1][2]) 5(nums[1][1]) 4(nums[1][0])-- 59 | # 7(nums[2][0]) 8(nums[2][1]) 9(nums[2][2]) 6(nums[2][3]) 60 | # | 61 | # | 62 | 63 | # """ 64 | # # for i in range(len(nums)): 65 | # # if i%2==0: 66 | # # #move forward 67 | # # pass 68 | # # else: 69 | # # #move backward 70 | # # pass 71 | 72 | # # nums = [ 73 | # # [1,2,3,4], 74 | # # [4,5,6,4], 75 | # # [7,8,9,6], 76 | # # [7,8,9,10], 77 | # # ] 78 | 79 | 80 | # #Implementation of all Matrix operations 81 | 82 | # #Addition 83 | 84 | # matrix1 = [ 85 | # [1,2,3], 86 | # [4,5,6] 87 | # ] 88 | 89 | # matrix2 = [ 90 | # [1,5,4], 91 | # [7,8,9] 92 | # ] 93 | 94 | # addMatrix = [ 95 | # [0,0,0], 96 | # [0,0,0] 97 | # ] 98 | 99 | # for i in range(len(matrix1)): 100 | # for j in range(len(matrix2)): 101 | # addMatrix[i][j] = matrix1[i][j] + matrix2[i][j] 102 | 103 | # print(addMatrix) 104 | 105 | # #Subtraction 106 | 107 | # matrix1 = [ 108 | # [1,2,3], 109 | # [4,5,6] 110 | # ] 111 | 112 | # matrix2 = [ 113 | # [1,5,4], 114 | # [7,8,9] 115 | # ] 116 | 117 | # diffMatrix = [ 118 | # [0,0,0], 119 | # [0,0,0] 120 | # ] 121 | 122 | # for i in range(len(matrix1)): 123 | # for j in range(len(matrix2)): 124 | # addMatrix[i][j] = matrix1[i][j] - matrix2[i][j] 125 | 126 | 127 | #Mulitplication 128 | #Note: columns in 1st matrix and rows in second matrix must be same 129 | 130 | matrix1 = [ 131 | [1,2,3], 132 | [4,5,6], 133 | [7,8,9] 134 | ] 135 | 136 | matrix2 = [ 137 | [9,8,7], 138 | [6,5,4], 139 | [3,2,1] 140 | ] 141 | 142 | multiplyResultMatrix = [ 143 | [0,0,0], 144 | [0,0,0], 145 | [0,0,0] 146 | ] 147 | 148 | for row in range(len(matrix1)): 149 | for column in range(len(matrix2)): 150 | for k in range(len(matrix2[column])): 151 | multiplyResultMatrix[row][column]+= matrix1[row][k] * matrix2[k][column] 152 | 153 | print(multiplyResultMatrix) -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 1/introductionToStringExample.py: -------------------------------------------------------------------------------- 1 | # #String: it is collection/sequence of characters(letters + numbers + special symbols) enclosed with single, double, and triple quotation mark. 2 | 3 | # #Examples: 4 | # studentName = "Rakesh" 5 | # favoriteLetter = 'a' 6 | # accountNumber = "1232323232" 7 | # ifscCode = "BOB3423D" 8 | # panCardNumber = "ATFSH2312H" 9 | # adhaarCardNumber = "2932938983" 10 | # mobileNumber = "9888232823" 11 | # password = "rakesh@12312" 12 | # pincode = "201301" 13 | # msg = "Hi, I'm rakesh from Patna, and learning about Python in Chitkara University." 14 | 15 | # #Point 2: Like list, string also follows 0 based indexing, meaning that first letter is at index 0, second is at index 1 and so on. 16 | 17 | # str = "Chitkara" 18 | 19 | # # print(str) 20 | # # print(str[0]) 21 | # # print(str[3]) 22 | 23 | # #Check numbers of characters in string - using len(iterable) 24 | # print(len(str)) 25 | 26 | # #Print characters using loop: 27 | 28 | # #1st way: 29 | 30 | # for char in str: 31 | # print(char, end=" ") 32 | 33 | 34 | # print() 35 | 36 | # #1st way: 37 | 38 | # for i in range(len(str)): 39 | # print(str[i], end=" ") 40 | 41 | 42 | #Example 1 : Given below string check how many vowels are there in the below string. 43 | 44 | # #1st Way 45 | # str = "apple" 46 | # vowels = "aeiou" 47 | # count = 0 48 | # for char in str: 49 | # if char in vowels: 50 | # count+=1 51 | 52 | # print(f"Vowels in {str} are {count}") 53 | 54 | # #2nd Way 55 | 56 | # # result = sum([1 for char in str if char in vowels]) 57 | # # print(result) 58 | 59 | # # print(sum([1 for char in str if char in vowels])) 60 | 61 | 62 | # #Point 3: 63 | # # String is immutable(unchangable) where as list is mutable(changable). 64 | # #Other Words, once you've declared a string then you can not change/modify/update it as it is immutable(unchangable). 65 | # #Note: But you can replace/reassign the value of string. 66 | 67 | 68 | # #Exampels: 69 | 70 | 71 | # #List: mutable(changable) 72 | # # nums = [1,2,3,4,5,6] 73 | 74 | # # nums[1] = 10 #modified the existing element of nums list at index 1 75 | 76 | # # print(nums) 77 | 78 | # # #String: immutable(unchangable) 79 | # # password = "rekesh@123" 80 | 81 | # # # password[0] = "m" #Trying to modify the char of the password string at index 0 which is not possible as string is immutable. 82 | 83 | # # password = "mekesh@123" #replacement/reassignment - which is possible 84 | 85 | # # print(password) 86 | 87 | 88 | # #Example 1: Given below string your task is to change the first character with M 89 | 90 | # # str = "Rupesh" 91 | 92 | # # strList = [char for char in str] 93 | 94 | # #1st Way: 95 | # # strList = [] 96 | 97 | # # for char in str: 98 | # # strList.append(char) 99 | 100 | # # print(strList) 101 | 102 | # # strList[0] = "M" 103 | # # print(strList) 104 | 105 | # # udpatedStr = "" 106 | # # for ele in strList: 107 | # # udpatedStr+=ele 108 | 109 | # # print(udpatedStr) 110 | 111 | # #2nd Way: 112 | # #str = "Rupesh" 113 | # # updatedStr = "M" + str[1:] 114 | # # print(updatedStr) #Mupesh 115 | 116 | 117 | # #Example 2: Given a string in small case your task is to convert into capital case without using inbuilt function. 118 | 119 | # name = "chitkara" 120 | 121 | # def myUpper(str): 122 | # smallCaseLetter = "abcdefghijklmnopqrstuvwxyz" 123 | # capitalCaseLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 124 | 125 | # # updatedString = "" 126 | 127 | # # for char in str: 128 | # # for i in range(len(smallCaseLetter)): 129 | # # if char == smallCaseLetter[i]: 130 | # # updatedString+= capitalCaseLetter[i] 131 | # # return updatedString 132 | 133 | 134 | # # print(myUpper("chitkara")) 135 | # # print(myUpper("apple")) 136 | 137 | 138 | # # #Example 3: Given list of string, your task is to capital those which are starting with "j" 139 | 140 | # # langs = ["java", "Python", "c", "javascript", "r"] 141 | 142 | # # for i in range(len(langs)): 143 | # # name = langs[i] 144 | # # if name[0]=="j": 145 | # # langs[i] = myUpper(langs[i]) 146 | 147 | # # print(langs) 148 | 149 | 150 | # #string slicing - extacting the some portion from the original string, and it is always in continuous manner. 151 | 152 | # """ 153 | # sytax: 154 | 155 | # [startPoint:endPoint:step] #ByDefault - startPoint - 0, endPoint - end of given String, step: 1 156 | 157 | # stringVariableName[:] - startPoint - 0, endPoint - end of given String, step: 1 158 | 159 | # stringVariableName[1:10:2] - startingPoint - 1, endPoint <10, step - 2 at a time. 160 | 161 | # """ 162 | 163 | 164 | # # str = "chitkara" 165 | 166 | # # print(str[:]) 167 | # # print(str[:4]) 168 | # # print(str[::2]) 169 | # # print(str[2:]) 170 | # # print(str[::-1]) 171 | # # print(str[:-4:-1]) 172 | 173 | # #Example: given a string below, check that string is palindrome or not. 174 | 175 | # str1 = "madam" #Palindrome 176 | # str2 = "car" #Not Palindrome 177 | 178 | # str1ReverseForm = "" 179 | # for i in range(len(str1)-1,-1,-1): 180 | # str1ReverseForm+=str1[i] 181 | 182 | # if str1 == str1ReverseForm: 183 | # print("Palindrome") 184 | # else: 185 | # print("Not Palindrome") 186 | 187 | # print("-------------------------------------") 188 | 189 | # #Shorthand way: 190 | # print("Palindrome" if str1==str1[::-1] else "Not Palindrome") -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 2/StringInbuiltFunctionExample.py: -------------------------------------------------------------------------------- 1 | # String Inbuilt Functions: 2 | # Capitalize(), count(), endswith, startswith, find, index, isalpha, isnum, isdigit, islower, isnumeric, isupper, lower, max, min, replace, splits with, strip 3 | 4 | #lower() - it converts string into lower case. 5 | 6 | # str = "CHITKARA" 7 | # print(str.lower()) # chitkara 8 | 9 | #upper() - it converts string into upper case. 10 | 11 | # str = "chitkara" 12 | # # str1 = str.upper() 13 | # print(str.upper()) # CHITKARA 14 | # print(str) # chitkara 15 | 16 | #capitalize() - it converts the first char/letter of string into upper case. 17 | 18 | # str = "chitkara university" 19 | # print(str.capitalize()) 20 | 21 | #title() - it converts each word first letter into capital in the string. 22 | 23 | # str = "chitkara university" 24 | 25 | # print(str.title()) 26 | 27 | 28 | #startswith(string) - it checks if the original string is starting with given string or not, if yes then it returns True if not then it returns False. 29 | 30 | 31 | # str = "hello world" 32 | # print(str.startswith("h")) #True 33 | # print(str.startswith("Hello")) #False 34 | # print(str.startswith("hello")) 35 | 36 | 37 | 38 | #endswith(string) - it checks if the original string is ending with given string or not, if yes then it returns True if not then it returns False. 39 | 40 | 41 | # str = "hello world" 42 | # print(str.endswith("h")) #False 43 | # print(str.endswith("d")) #True 44 | # print(str.endswith("world")) #True 45 | # print(str.endswith("ld")) #True 46 | 47 | #Problem Statement: 48 | # Given list of string, your task is to capital those which are starting with "J" 49 | 50 | # langs = ["Java", "Python", "C", "Javascript", "R"] 51 | 52 | # #Solution 1: 53 | # for i in range(len(langs)): 54 | # if langs[i].startswith("J"): 55 | # langs[i] = langs[i].upper() 56 | 57 | # print(langs) 58 | 59 | #Solution 2: List Comprehension. 60 | 61 | #count(str) - it counts how many time particular char/sequence are there inside original string. 62 | 63 | #functionality - it returns the count of specific element if not available then it returns 0 as count. 64 | 65 | # str = "helloll" 66 | 67 | # print(str.count("l")) 68 | # print(str.count("p")) 69 | # print(str.count("ll")) 70 | 71 | #find(string) - it checks particular string is available inside original string or not if not then it returns -1 else it return index 72 | 73 | 74 | # str = "hello world" 75 | 76 | # print(str.find("hello")) #0 77 | # print(str.find("world")) #6 78 | # print(str.find("python")) #-1 79 | 80 | #index(string) - it returns the index of particular string in the original string. 81 | 82 | 83 | # str = "hello world" 84 | 85 | # print(str.index("e")) #1 86 | # print(str.index("ll")) #1 87 | # print(str.index("p")) #ValueError - substring is not found. 88 | 89 | #split(seperator) - it seperates the string by given seperator and converts into list. 90 | 91 | #Note: if you don't define any seperator for spliting then by default the seperator is " " 92 | 93 | # langs = "java python javascript .net" 94 | # print(langs.split()) 95 | 96 | # langs = "java-python-javascript-.Net" 97 | # print(langs.split("-")) 98 | 99 | 100 | #Problem: take number input from user by space seperated like below and find out the maximum value in the list. 101 | 102 | # input = "12 34 45 23 12" 103 | 104 | # inputValue = input("Enter Numbers: ") 105 | # strList = inputValue.split(" ") 106 | # numList = [int(char) for char in strList] 107 | 108 | # print(max(numList)) 109 | 110 | # #shorthand way: 111 | 112 | # print(max([int(char) for char in input("Enter Numbers: ").split(" ")])) 113 | 114 | # print(max(list(lambda char: int(char), input("Enter Numbers: ").split(" ")))) 115 | 116 | 117 | #strip() - it removes front and back space of the strings. 118 | 119 | 120 | # str = " hello " 121 | # print(str) 122 | # print(str.strip()) 123 | 124 | #replace - it replaces the some portion of the string with char/sequence. 125 | 126 | # str = "hello universe" 127 | 128 | # print(str.replace("universe" , "world")) 129 | 130 | # print(str.replace("ratan tata" , "world")) 131 | 132 | 133 | #isalpha() - it checks string is containing only alphabets or not. 134 | 135 | # str = "hello" 136 | 137 | # print(str.isalpha()) #True 138 | 139 | # str1 = "hello123" 140 | 141 | # print(str1.isalpha()) #False 142 | 143 | 144 | #isnumeric() - it checks if a string is containing only numbers 145 | 146 | # str = "1232323" 147 | 148 | # print(str.isnumeric()) #True 149 | 150 | # str1 = "hello123121" 151 | 152 | # print(str1.isnumeric()) #False 153 | 154 | 155 | #isalnum() - it checks if given string is conatining either alphabets or numbers. 156 | 157 | # str = "hello123" 158 | 159 | # print(str.isalnum()) 160 | 161 | # str = "hello" 162 | 163 | # print(str.isalnum()) 164 | 165 | #isupper() 166 | 167 | # str = "CHITKARA" 168 | 169 | # print(str.isupper()) #True 170 | 171 | 172 | #python inbuilt function for strings operation: 173 | 174 | #max(Iterable) 175 | #min(Iterable) 176 | 177 | #Note: in the case, string max() and min() functions compares according to the characters ascii value: 178 | 179 | #ascii table reference: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html 180 | 181 | # str = "world" 182 | 183 | # print(max(str)) 184 | # print(min(str)) 185 | -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 2/notepadApplicationFuncitionalityExample.py: -------------------------------------------------------------------------------- 1 | #Problem Statement: Creating a Notepad and implementing find, replace and other useful functions 2 | 3 | 4 | #Solution: 5 | 6 | print("--------------WELCOME TO MY APPLICAITON---------------") 7 | 8 | str = input("Enter the Text: ") 9 | 10 | def notepadMenu(): 11 | print("1. To Find") 12 | print("2. To Replace") 13 | print("3. To Count Sepecfic Char/Sequence") 14 | print("4. Print Text") 15 | print("5. Re-Enter the Text") 16 | print("6. Exit") 17 | 18 | while True: 19 | notepadMenu() 20 | choice = int(input("Enter Your Choice: ")) 21 | 22 | if choice == 1: 23 | text = input("Enter Text to Find: ") 24 | msg = "" 25 | if str.find(text)!=-1: 26 | msg = "Text is available in the original text." 27 | else: 28 | msg = "Text is not available in the original text." 29 | print("--------------------------------------------") 30 | print(msg) 31 | print("--------------------------------------------") 32 | elif choice == 2: 33 | replaceText = input("What to Replace: ") 34 | msg = "" 35 | if str.find(replaceText)!=-1: 36 | replaceValue = input("Text for Replacing: ") 37 | str = str.replace(replaceText, replaceValue) 38 | msg = "Text has replaced successfully." 39 | else: 40 | msg = "Text is not found in the original string." 41 | print("--------------------------------------------") 42 | print(msg) 43 | print("--------------------------------------------") 44 | elif choice == 3: 45 | #Implement the functionality for counting particular char/sequence 46 | pass 47 | elif choice == 4: 48 | print("--------------------------------------------") 49 | print(str) 50 | print("--------------------------------------------") 51 | elif choice == 5: 52 | #Implement the functionality for re entring the text 53 | pass 54 | elif choice == 6: 55 | res = input("do you want to continue(y/n): ") 56 | if res in ['n', 'N']: 57 | print("Thank you for using my application.") 58 | break 59 | else: 60 | print("Invalid choice, please try again.") -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 3/introductionToTupleExample.py: -------------------------------------------------------------------------------- 1 | #tuple - it is a data structure, ordered, and immutable collection of elements 2 | 3 | #Characteristic of Tuple: 4 | #1. ordered 5 | #2. immutable 6 | #3. follows indexing 7 | #4. allow duplicate 8 | 9 | #decalaration of tuple 10 | 11 | #syntax - variableName = () 12 | 13 | # nums = () #here, we created a tuple with name nums. 14 | # print(nums) 15 | # print(type(nums)) # 16 | 17 | #Note: once tuple is immutable, therefore, addition, updation, and modification of any element is not allowed. 18 | 19 | #nums = (1,2,3,4,5,6,7,8,9,10) 20 | 21 | #indexing 22 | # print(nums[4]) 23 | # print(nums[len(nums)-1]) 24 | 25 | #support -ve indexing like list and string 26 | #print(nums[-1]) 27 | 28 | #looping in tuple 29 | # #1st way: 30 | # for item in nums: 31 | # print(item, end=" ") 32 | 33 | # print() 34 | 35 | # #2nd way: 36 | # for i in range(len(nums)): 37 | # print(nums[i], end=" ") 38 | 39 | 40 | #condition inside loop: 41 | 42 | #Problem: print only even numbers 43 | 44 | # for item in nums: 45 | # if item%2==0: 46 | # print(item, end=" ") 47 | 48 | #tuple slicing 49 | 50 | # fruits = ("Papaya", "Mango", "Orange", "Grapes", "Guava") 51 | 52 | # print(fruits[1:]) 53 | # print(fruits[:]) 54 | # print(fruits[::-1]) 55 | 56 | #immutability 57 | 58 | # fruits = ("Papaya", "Mango", "Orange", "Grapes", "Guava") 59 | 60 | # fruits[0] = "Kiwi" #TypeError: 'tuple' object does not support item assignment 61 | 62 | 63 | #packing and upacking - tuple and list. 64 | 65 | #packing - store multiple elements into one variable 66 | # #Example: 67 | # nums = [1,2,3,4,5] #packing 68 | 69 | # #unpacking - expending the list or tuple into individual variables. 70 | 71 | # a,*b= nums #unpacking 72 | # print(a) 73 | # print(b) 74 | 75 | 76 | fruits = ("Papaya", "Mango", "Orange", "Grapes", "Guava") #packing 77 | 78 | 79 | # fruit1, fruit2, fruit3, fruit4, fruuit5 = fruits 80 | 81 | # print(fruit1, fruit2) 82 | 83 | # fruit1 , *restFruits = fruits 84 | 85 | # print(fruit1, restFruits) 86 | 87 | #Note: in the case of tuple unpacking, while *arws opeator it returns always list. 88 | 89 | #inbuilt function fpr tuple: 90 | 91 | nums = (1,2,3,4,5) 92 | 93 | print(sum(nums)) 94 | print(max(nums)) 95 | print(min(nums)) 96 | print(len(nums)) 97 | print(sorted(nums, key=None, reverse=True)) 98 | 99 | #Ended. 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 4/introductionToDictionaryExample.py: -------------------------------------------------------------------------------- 1 | #Dictionary: It is a data structure which is use to store the data in the form key-value pair. 2 | 3 | #Note: key-value pair is also known as one item/entry in the dictionary. 4 | 5 | #Importnat Points 6 | # 1. Unordered. 7 | # 2. Mutable 8 | # 3. Accessing through Keys 9 | # 4. Keys are unique whereas values can be duplicate. 10 | # 5. Keyas are always of string type whereas values can be any type. 11 | 12 | 13 | #Declaration of Dictionary 14 | 15 | #student = {} 16 | # student = dict() 17 | 18 | # print(student) 19 | # print("Empty Dictionary" if len(student)==0 else "Not Empty") 20 | 21 | 22 | # student = { 23 | # "name":"Pawan", 24 | # "marks":450, 25 | # "city":"Noida", 26 | # "skills":["HTML", "CSS", "JS"], 27 | # "subjects":("Maths", "Science", "English", "Computer"), 28 | # "isMarried":False 29 | 30 | # } 31 | 32 | # print(student) 33 | 34 | 35 | #How to add item/entry to the dictionary. 36 | 37 | student = {} 38 | 39 | #1. dictionaryName["keyName"] = value 40 | 41 | student["name"] = "Pawan" #additing one item where key is name and value is pawan 42 | 43 | student["city"] = "Noida" #additing one item where key is city and value is Noida 44 | 45 | student["age"] = 23 #additing one item where key is age and value is 23 46 | 47 | print(student) 48 | 49 | -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 4/introductionToSetExample.py: -------------------------------------------------------------------------------- 1 | #Set - it is a data structure which is collection of unique elements. 2 | 3 | #Points about Set: 4 | #1. Unordered 5 | #2. Mutable 6 | #3. No Indexing 7 | #4. Unique elements 8 | 9 | #Decalration of Set 10 | 11 | # list = [1,2,3,4,5,2,3,1,2,1,2,3,4] 12 | 13 | # nums = set() 14 | # print(nums) # 15 | # print(type(nums)) # 16 | 17 | # nums = {1,2,3,4,5} 18 | # print(nums) 19 | 20 | # personSet = set() 21 | 22 | # #How to add elements to the set. 23 | 24 | # personSet.add("Rakesh") 25 | # personSet.add("Pawan") 26 | # personSet.add("Siya") 27 | # personSet.add("Kunal") 28 | 29 | # personSet.add("Rakesh") 30 | 31 | # print(personSet) 32 | 33 | #How to add multiple element to the set? 34 | 35 | # personSet.update(["Shivangi", "Rohan"]) 36 | 37 | # print(personSet) 38 | 39 | # #How to remove/delete element from set? 40 | 41 | # #remove('') 42 | 43 | # personSet.remove('Rohan') 44 | # #personSet.remove('Sita') #Error if element is not present inside set. 45 | # personSet.discard('Sita')#No Error if element is not inside set. 46 | 47 | # personSet.discard('Rakesh') 48 | # print(personSet) 49 | 50 | # #pop() - it deletes arbitary element 51 | 52 | # personSet.pop() 53 | # print(personSet) 54 | 55 | 56 | # numSet = {1,2,3,4,5,5,6,4,3,2,1} 57 | # print(numSet) 58 | # # print(len(numSet)) 59 | 60 | # #looping set 61 | 62 | # for item in numSet: 63 | # print(item, end=" ") 64 | 65 | 66 | #Problem 1: given a list of numbers your task is to print only unique numebers. 67 | 68 | # numsList = [1,2,3,4,5,6,3,2,1,2,3,5,6,7,2,3,8,7,8,9,10] 69 | # numsSet = set(numsList) 70 | # print(numsSet) 71 | 72 | #Set Operations: 73 | 74 | # set1 = {1,2,3} 75 | # set2 = {3,4,5} 76 | 77 | # #union - | 78 | # unionResult = set1 | set2 79 | # print(unionResult) #{1,2,3,4,5} 80 | 81 | # #intersection - & 82 | 83 | # intersectionResult = set1 & set2 84 | # print(intersectionResult) 85 | 86 | 87 | #copy(), clear() 88 | 89 | nums = {1,2,3,4,5,6} 90 | 91 | # print(f"Before Clearing the set: {nums}") 92 | 93 | # nums.clear() 94 | 95 | # print(f"After Clearing the set: {nums}") 96 | 97 | # numsSet = nums.copy() 98 | # print(numsSet) 99 | 100 | 101 | -------------------------------------------------------------------------------- /Unit 3/Sprint 1/Day 5/moreAboutDictionaryExample.py: -------------------------------------------------------------------------------- 1 | #Dictionary: It is a data structure which is use to store the data in the form key-value pair. 2 | 3 | #Note: key-value pair is also known as one item/entry in the dictionary. 4 | 5 | #Importnat Points 6 | # 1. Unordered. 7 | # 2. Mutable 8 | # 3. Accessing through Keys 9 | # 4. Keys are unique whereas values can be duplicate. 10 | # 5. Keyas are always of string type whereas values can be any type. 11 | 12 | 13 | #Declaration of Dictionary 14 | 15 | #student = {} 16 | # student = dict() 17 | 18 | # print(student) 19 | # print("Empty Dictionary" if len(student)==0 else "Not Empty") 20 | 21 | 22 | # student = { 23 | # "name":"Pawan", 24 | # "marks":450, 25 | # "city":"Noida", 26 | # "skills":["HTML", "CSS", "JS"], 27 | # "subjects":("Maths", "Science", "English", "Computer"), 28 | # "isMarried":False 29 | 30 | # } 31 | 32 | # print(student) 33 | 34 | 35 | #How to add item/entry to the dictionary. 36 | 37 | # student = {} 38 | 39 | # #1. dictionaryName["keyName"] = value 40 | 41 | # student["name"] = "Pawan" #additing one item where key is name and value is pawan 42 | # student["city"] = "Noida" #additing one item where key is city and value is Noida 43 | # student["age"] = 23 #additing one item where key is age and value is 23 44 | 45 | 46 | # print(student) 47 | 48 | 49 | # employee = {} 50 | 51 | #1. dictionaryName['KeyName'] = value 52 | 53 | # employee["name"] = "Rakesh" 54 | # employee["salary"] = 45000 55 | # employee["city"] = "Delhi" 56 | 57 | # print(employee) 58 | 59 | #2. using update({}) 60 | 61 | #to add/update multiple entries/items to the dictionary 62 | #sytnax = dictionaryName.update({}) 63 | 64 | # employee.update({'name':"Rakesh", "city":"Noida", "salary":50000}) 65 | 66 | # print(employee) 67 | 68 | 69 | #how to access the value? - using keyName 70 | 71 | student = { 72 | "name":"Pawan", 73 | "marks":450, 74 | "city":"Noida", 75 | "skills":["HTML", "CSS", "JS"], 76 | "subjects":("Maths", "Science", "English", "Computer"), 77 | "isMarried":False 78 | 79 | } 80 | 81 | #sytanx = dictionaryName['keyName'] 82 | # print(student['name']) 83 | # print(student['city']) 84 | # print(student['skills'][1]) 85 | 86 | #above student is skilled in html or not. 87 | 88 | # if "HTML" in student['skills']: 89 | # print("Yes, he is skilled") 90 | # else: 91 | # print("Yes, he is not skilled") 92 | 93 | 94 | # if key doesn't exist 95 | 96 | # print(student['age']) #KeyError: 'age' 97 | 98 | #dictionaryName.get('keyName', None) - it doesn't give any error if the key is not available inside dictionary instead it gives default value as None that you can change. 99 | 100 | 101 | # print(student.get('age')) 102 | # print(student.get('age', "Key is not available inside dictionary")) 103 | 104 | 105 | #how to update the value of dictionary? - using keyName 106 | 107 | 108 | #1. dictionaryName['keyName'] = value 109 | 110 | #updating value Pankaj for key name 111 | # student['name'] = "Pankaj" 112 | # student['city'] = "Patna" 113 | 114 | # print(student) 115 | 116 | #2. to update multiple entries/items - using update({}) 117 | 118 | # student.update({'name':"Chintu", "city":"Haryana"}) 119 | 120 | # print(student) 121 | 122 | 123 | -------------------------------------------------------------------------------- /Unit 3/Sprint 2/Day 1/moreAboutDictionaryExample.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Unit 3/Sprint 2/Day 1/moreAboutDictionaryExample.py -------------------------------------------------------------------------------- /Unit 3/Sprint 3/Day 1/moreAboutDictionaryExample.py: -------------------------------------------------------------------------------- 1 | #how to delete/remove an entry/item from the dictionary? 2 | 3 | #Initialization at the time of declaration 4 | # student = { 5 | # "name":"Chintu", 6 | # "age":45, 7 | # "city":"Noida", 8 | # "isMarried": True, 9 | # "skills":["HTML", "CSS", "JS"] 10 | # } 11 | 12 | #Delete Entry using del keyword 13 | #Syntax - del dictionaryName[keyName] 14 | 15 | # print(student) 16 | 17 | # del student["age"] 18 | 19 | # print(student) 20 | 21 | # del student["age"] #KeyError: 'age' 22 | 23 | #using pop('keyName', defaultValue) 24 | 25 | #syntax - dictionaryName.pop(keyName, defaultValue) #if you're not mentioned the default value and entry is also not available with given key then default value is None(Nothing, absence of value, Null) 26 | 27 | #Note: it returns the value of given key 28 | 29 | # print(student) 30 | 31 | # removedAgeKeyValue = student.pop("age") 32 | 33 | # print(removedAgeKeyValue) 34 | 35 | # print(student) 36 | 37 | 38 | # removedAgeKeyValue = student.pop("age", None) 39 | 40 | # removedAgeKeyValue = student.pop("age", "It is no more part of student dictionary") 41 | 42 | # print(removedAgeKeyValue) 43 | 44 | 45 | #using popItem() 46 | 47 | #Syntax - dictionaryNmae.popItem() - it deletes the most recent added entry to the dictionary and returns it. 48 | 49 | # mostRecentAddedEntry = student.popitem() 50 | 51 | # print(mostRecentAddedEntry) 52 | 53 | # print(student) 54 | 55 | #Inbuilt function of dictionary: 56 | 57 | # student = { 58 | # "name":"Chintu", 59 | # "age":45, 60 | # "city":"Noida", 61 | # "isMarried": True, 62 | # "skills":["HTML", "CSS", "JS"] 63 | # } 64 | 65 | #keys() 66 | #syntax - dictionaryName.keys() 67 | 68 | # print(student.keys()) 69 | 70 | # studentKeys = student.keys() 71 | 72 | # print(studentKeys[0]) #TypeError: 'dict_keys' object is not subscriptable 73 | 74 | # studentKeys = list(student.keys()) 75 | 76 | # print(studentKeys[0]) 77 | 78 | # for key in student.keys(): 79 | # print(key, end=" ") 80 | 81 | 82 | #values() 83 | 84 | # print(student.values()[0]) #TypeError: 'dict_values' object is not subscriptable 85 | 86 | # studentValues = list(student.values()) 87 | 88 | # print(studentValues[0]) 89 | 90 | 91 | # for value in student.values(): 92 | # print(value, end=" ") 93 | 94 | 95 | #items() - return list of tuples where each tuple is item(key, value) 96 | 97 | # print(student.items()) 98 | 99 | # studentItems = list(student.items 100 | # ()) 101 | 102 | # # print(studentItems[0][0]) 103 | 104 | # key, value = studentItems[0] # ('name', 45) 105 | 106 | # print(key, value) 107 | 108 | # print(list(student.items())) 109 | 110 | # [('name', 'Chintu'), ('age', 45), ('city', 'Noida'), ('isMarried', True), ('skills', ['HTML', 'CSS', 'JS'])] 111 | 112 | # for chintu, babita in student.items(): 113 | # print(chintu, babita) 114 | 115 | # student = { 116 | # "name":"Chintu", 117 | # "age":45, 118 | # "city":"Noida", 119 | # "isMarried": True, 120 | # "skills":["HTML", "CSS", "JS"] 121 | # } 122 | 123 | #Problem 1: given student dictionary, your task is to delete an entry/item where key is age 124 | 125 | # del student["age"] 126 | # student.pop("age") 127 | 128 | #Problem 2: given student dictionary, your task is to update the name value as "Chunnu" 129 | 130 | # #First Way 131 | # student["name"] = "Chunnu" 132 | 133 | 134 | # #Second Way 135 | # student.update({"name":"Chunnu"}) 136 | 137 | #Problem: Given below employee dictionary, your task is to get homeAddress city 138 | # employee = { 139 | # "name":"Munna", 140 | # "salary":100000, 141 | # "department":"IT", 142 | # "designation":"SDE-1", 143 | # "address":{ 144 | # "homeAddress":{ 145 | # "city":"Noida", 146 | # "state":"UP" 147 | # }, 148 | # "officeAdress":{ 149 | # "city":"Agra", 150 | # "state":"UP" 151 | # } 152 | # } 153 | # } 154 | 155 | 156 | # print(employee["address"]["homeAddress"]["city"]) 157 | 158 | 159 | #Problem 1: Guess the output for the following statement: 160 | 161 | # student = { 162 | # "studentName":"Madan", 163 | # "studentAge":23, 164 | # "isMarried":False, 165 | # "Skills":["HTML", "CSS", "JS"] 166 | # } 167 | 168 | #print(student["city"])#KeyError: 'city' 169 | 170 | # print(student.get("city", None)) 171 | 172 | # print(student.get("city", "Entry is not found with this key")) 173 | 174 | # nums = {} 175 | 176 | # nums[1] = 1 177 | 178 | #nums = {'1':1} 179 | 180 | # print(nums.get(1)) #1 181 | # print(nums.get(2)) #None 182 | # print(nums.get(2,0)) #0 183 | 184 | # nums[2] = 1 185 | 186 | # #nums = '1':1, '2':1} 187 | 188 | # print(nums) 189 | 190 | # print(type(list(nums.keys())[0])) 191 | 192 | # if 2 in nums: 193 | # print("Found") 194 | # else: 195 | # print("Not Found") 196 | 197 | #Problem: Given a string, your task is to find out the count of vowels and consonants in the following format. 198 | 199 | #input - str = "apple" 200 | #output= {'vowels':2, 'consonants':3} 201 | 202 | #Solution 1: 203 | 204 | # str = "apple" 205 | 206 | # vowels = 0 207 | # consonants = 0 208 | 209 | # for char in str: 210 | # if char in "aeiou": 211 | # vowels+=1 212 | # else: 213 | # consonants+=1 214 | 215 | # print({"vowels":vowels, "consonants":consonants}) 216 | 217 | # #Solution 2: 218 | 219 | # vowels = sum([1 for char in str if char in "aeiou"]) 220 | # consonants = sum([1 for char in str if char not in "aeiou"]) 221 | 222 | # print({"vowels":vowels, "consonants":consonants}) 223 | 224 | 225 | #Problem 2 : Given a string below, your task is to find out the freequency of character. 226 | 227 | #input - str = "apple" 228 | #output - {'a':1, 'p':2, 'l':1, 'e':1} 229 | 230 | #Solution 1: 231 | # str = "apple" 232 | # charFrequency = {} 233 | 234 | # for char in str: 235 | # if char in charFrequency: 236 | # charFrequency[char]= charFrequency[char] + 1 237 | # else: 238 | # charFrequency[char]=1 239 | 240 | #Solution 2: 241 | 242 | # str = "apple" 243 | # charFrequency = {} 244 | 245 | # for char in str: 246 | # charFrequency[char]= charFrequency.get(char, 0) + 1 247 | 248 | 249 | # #Solution 3: 250 | 251 | # result = {char: str.count(char) for char in set(str)} 252 | 253 | #Problem: given a number list, your task is to find out the frequency of number. 254 | 255 | # nums = [1,2,3,2,3,2,1,3,1,2,3,2,1,4] 256 | 257 | # dict = {} 258 | 259 | # for num in nums: 260 | # dict[num] = dict.get(num, 0) + 1 261 | 262 | 263 | #Problem: Given a string, your task is to find out the frequency of word. 264 | 265 | # str = "hello hello world hello hi hi bye" 266 | # strList = str.split() 267 | # #print(strList) #['hello', 'hello', 'world','hello', 'hi', 'hi', 'bye'] 268 | 269 | # charFrequency = {} 270 | 271 | # for word in strList: 272 | # charFrequency[word]= charFrequency.get(word, 0) + 1 273 | 274 | #JSON and its relation with python dictionary. 275 | 276 | #JSON: it stands for Javascript Object Notation which is light weight data interchange format and it is easy for humans to read and write, and machine to parse and generate. 277 | 278 | 279 | #data exchange 280 | 281 | """ 282 | 283 | Client Side(Frontent) 284 | Request | 285 | --------------------> | JSON 286 | Response | 287 | <------------------- 288 | Server Side(Backend) 289 | 290 | """ 291 | 292 | #Syntax of json - it is 100% similar to python dictionary 293 | 294 | #Python Dictionary 295 | # studentDict = { 296 | # "name":"Pawan", 297 | # "age":23, 298 | # "city":"Noida" 299 | # } 300 | 301 | #Note: json is a textual/string type data. 302 | 303 | #Python Dictionary 304 | # studentJson = '{"name":"Pawan","age":23,"city":"Noida"}' 305 | 306 | # print(type(studentDict)) 307 | # print(type(studentJson)) 308 | 309 | #How to convert dictionary to json? 310 | 311 | employee = { 312 | "name":"Pawan", 313 | "age":23, 314 | "city":"Noida" 315 | } 316 | 317 | import json 318 | 319 | employeeJson = json.dumps(employee) 320 | print(employeeJson) 321 | 322 | print(type(employeeJson)) 323 | 324 | #Convet json into python dictionary 325 | 326 | employeeDict = json.loads(employeeJson) 327 | 328 | print(employeeDict) 329 | print(type(employeeDict)) 330 | 331 | 332 | 333 | -------------------------------------------------------------------------------- /Unit 3/Sprint 3/Day 2/moreAboutDictionaryExample.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Unit 3/Sprint 3/Day 2/moreAboutDictionaryExample.py -------------------------------------------------------------------------------- /Unit 3/Sprint 3/Day 3/recap.py: -------------------------------------------------------------------------------- 1 | #Any Doubt in ST-2 Syllabus and in 2 | 3 | #String Contest Problems Discusion: 4 | 5 | #Even Length String: abcxyz 6 | #Odd Length String: abcdxyz 7 | 8 | """ 9 | even string = abcxyz = length 6//2 = 3 10 | firstString = string[:3:] 11 | secondString = string[3::] 12 | print(fistString[::-1]+secondString[::-1]) 13 | 14 | 15 | odd string = abcdxyz = length 6//2 = 3 16 | firstString = abc 17 | left - d - position - 3 18 | secondString = xyz 19 | print(fistString[::-1]+ string[3] +secondString[::-1]) 20 | 21 | """ 22 | 23 | 24 | #How to convert a string to list using inbuilt function? - split() 25 | 26 | # str = "apple" 27 | 28 | # strList = str.split(" ") 29 | # print(strList) 30 | 31 | # strList.append("banana") 32 | 33 | # #How to convert a list to string using inbuilt function? - join() 34 | 35 | # newString = "".join(strList) 36 | # print(newString) 37 | 38 | 39 | #Problem 1: Given list of student dictionary: 40 | 41 | 42 | studentList = [ 43 | { 44 | "name":"Pawan", 45 | "age":23, 46 | "city":"Noida", 47 | "university":"Chitkara University" 48 | }, 49 | { 50 | "name":"Sunil", 51 | "age":22, 52 | "city":"Delhi", 53 | "university":"Chandigarh University" 54 | }, 55 | { 56 | "name":"Chintu", 57 | "age":24, 58 | "city":"Delhi", 59 | "university":"Delhi University" 60 | }, 61 | { 62 | "name":"Rohan", 63 | "age":22, 64 | "city":"Gurugram", 65 | "university":"Delhi University" 66 | }, 67 | { 68 | "name":"Sita", 69 | "age":20, 70 | "city":"Noida", 71 | "university":"Sharda University" 72 | }, 73 | { 74 | "name":"Prince", 75 | "age":12, 76 | "city":"Haryana", 77 | "university":"Amity University" 78 | }, 79 | ] 80 | 81 | # for item in studentList: 82 | # if item["university"]=="Delhi University": 83 | # print(item["name"]) 84 | 85 | # for item in studentList: 86 | # if item["city"]=="Noida": 87 | # print(item["name"]) 88 | 89 | # studentFromNoida = list(filter(lambda student: student["city"]=="Noida",studentList)) 90 | 91 | # print(studentFromNoida) 92 | 93 | 94 | matrix = [ 95 | [1,2,3], 96 | [4,5,6], 97 | [7,8,9] 98 | ] -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 1/inputTakingExample.py: -------------------------------------------------------------------------------- 1 | #Problem: 10 Test Cases - 1 Test Case - 9 Test Cases are hidden 2 | 3 | #Input Taking: 4 | 5 | """ 6 | input: read the input statement carefully 7 | 8 | First Test Case: 9 | 4 3 10 | 1 2 3 11 | 4 5 6 12 | 7 8 9 13 | 3 2 1 14 | rows, columns = [int(n) for n in input().split()] 15 | list = [] 16 | # for row in range(rows): 17 | # list.append([int(num) for num in input().split()]) 18 | 19 | for row in range(rows): 20 | numlist = input().split() 21 | innerList = [] 22 | for num in numList: 23 | innerList.append(int(num)) 24 | list.append(innerList) 25 | 26 | 27 | 28 | 9 Test Cases - Hidden 29 | 30 | """ 31 | 32 | #Input taking in case of 2d list 33 | #solution 1 34 | # rows, columns = [int(n) for n in input().split()] 35 | 36 | # list = [] 37 | # for row in range(rows): 38 | # list.append([int(num) for num in input().split()]) 39 | 40 | # print(list) 41 | 42 | 43 | #solution 2 44 | # strList = input().split() 45 | # rows = int(strList[0]) 46 | # columns = int(strList[1]) 47 | 48 | # list = [] 49 | 50 | # for row in range(rows): 51 | # strs = input().split() 52 | # innerList = [] 53 | # for char in strs: 54 | # innerList.append(int(char)) 55 | # list.append(innerList) 56 | 57 | # print(list) -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 1/introductionToSortingAlgorithms.py: -------------------------------------------------------------------------------- 1 | #Algorithm: It is step by step solution for particular problem. 2 | 3 | #Note: for one problem,we can have n number of algorithms. 4 | 5 | 6 | #Sorting Algorithm: It is used to arrange the elements in specific order, commonly in ascending or descending order. 7 | 8 | #There are following sorting algorithms: 9 | #1. Selection Sort 10 | #2. Bubble Sort 11 | #3. Insertion Sort 12 | #4. Merge Sort 13 | #5. Quick Sort 14 | 15 | 16 | #Python Inbuilt function for sorting: 17 | #ascending - sorted(Iterable, Key=None, reversed=False) 18 | #descending - sorted(Iterable, Key=None, reversed=True) -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 1/selectionSortAlgorithmExample.py: -------------------------------------------------------------------------------- 1 | #Selection Sort: It is comparison based algorithm that works by dividing the list into sorted, unsorted part, and repeatedly searching mininum(ascending)/maximum(descending) element from unsorted part and swap with first element of unsorted part, and keep on doing this until list is sorted. 2 | 3 | #How does it work? - Ascending Order 4 | #1. Intial Setup: Start with the entire is as unsorted. 5 | #2. Find the Mininum Element: Find Mininum Element from unsorted part. 6 | #3. Swap: Swap the mininum element with first element of unsorted part. 7 | #4. Repeat: Repeat above process until the list is sorted. 8 | 9 | """ 10 | Example: Ascending Order 11 | list = [5,1,3,2,0] 12 | 13 | First Pass: Smaller Element in [5,1,3,2,0] is 0 then swap with 5 - [0,1,3,2,5] 14 | Second Pass: Smaller Element in [1,3,2,5] is 1 then swap with 1 - [0,1,3,2,5] 15 | Third Pass: Smaller Element in [3,2,5] is 2 then swap with 3 - [0,1,2,3,5] 16 | 17 | Example - Ascending order 18 | list = [7,0,4,6,1,5] 19 | 20 | First Pass: Smaller [7,0,4,6,1,5] 0 with swap with 7 [0,7,4,6,1,5] 21 | Second Pass: Smaller[7,4,6,1,5] 1 with swap with 7 [0,1,4,6,7,5] 22 | Third Pass: Smaller[4,6,7,5] 4 with swap with 4 [0,1,4,6,7,5] 23 | Fourth Pass: Smaller[6,7,5] 5 with swap with 6 [0,1,4,5,7,6] 24 | Fifth Pass: Smaller[7,6] 6 with swap with 7 [0,1,4,5,6,7] 25 | 26 | Descending Order - Try by yourself: 27 | 28 | 29 | list = [7,0,4,6,1,5] 30 | 31 | for i in range(len(list)-1): 32 | smallIndex = i 33 | for j in range(i+1, len(list)): 34 | if list[smallIndex] > list[j]: 35 | smallIndex = j 36 | list[i], list[smallIndex] = list[smallIndex], list[i] 37 | 38 | 39 | 40 | How to Swap Element? 41 | Problem 1: Swap two element without taking help of third variable. 42 | 43 | a = 4 44 | b = 5 45 | 46 | #Solution 1: with the help third variable 47 | temp = a 48 | a = b 49 | b = temp 50 | 51 | #Solution 1: withput the help third variable 52 | 53 | a , b = b, a 54 | 55 | 56 | #Example 2: 57 | list = [5,6,8] 58 | #Solution 1: with the help third variable 59 | temp = list[1] 60 | list[1] = list[2] 61 | list[2] = temp 62 | 63 | #Solution 1: withput the help third variable 64 | list[1], list[2] = list[2], list[1] 65 | 66 | """ 67 | 68 | #Ascending Order 69 | # list = [7,0,4,6,1,5] 70 | 71 | 72 | # print(f"Before Sorting: {list}") 73 | 74 | # for i in range(len(list)-1): 75 | # smallIndex = i 76 | # for j in range(i+1, len(list)): 77 | # if list[smallIndex] > list[j]: 78 | # smallIndex = j 79 | # list[i], list[smallIndex] = list[smallIndex], list[i] 80 | 81 | 82 | # print(f"After Sorting: {list}") 83 | 84 | 85 | #Descending Order: 86 | 87 | list = [7,0,4,6,1,5] 88 | 89 | 90 | print(f"Before Sorting: {list}") 91 | 92 | for i in range(len(list)-1): 93 | largeIndex = i 94 | for j in range(i+1, len(list)): 95 | if list[largeIndex] < list[j]: 96 | largeIndex = j 97 | list[i], list[largeIndex] = list[largeIndex], list[i] 98 | 99 | 100 | print(f"After Sorting: {list}") -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 2/binarySearchAlgorithmExample.py: -------------------------------------------------------------------------------- 1 | #Binary Search Algorithm: It is an efficient algorithm that on sorted list and divides the search interval in two halves, if the target element is greater than the mid element, then you search in right half, otherwise you search in left half. 2 | 3 | 4 | #How does it work? 5 | #1. Intial Setup: Start with sorted list 6 | #2. Divide the Search Interval: it divides the list by its search interval into two halves, and you will get the mid element index 7 | #3. Check for target: it checks if the target is greater then mid element then check in right half otherwise check in left half. 8 | 9 | 10 | """ 11 | list: [ 1,2,3,6,8,9,10,23] 12 | target = 3 13 | 14 | low, high = 0, len(list)-1 15 | while (low<=high): 16 | mid = (low+high)//2 17 | if list[mid]==target: 18 | print(mid) 19 | break 20 | elif target < list[mid]: 21 | high = mid - 1 22 | else: 23 | low = mid + 1 24 | 25 | """ 26 | 27 | list = [1,2,3,6,8,9,10,23] 28 | target = 2 29 | bag = -1 30 | low, high = 0, len(list)-1 31 | while (low<=high): 32 | mid = (low+high)//2 33 | if list[mid]==target: 34 | bag = mid 35 | break 36 | elif target < list[mid]: 37 | high = mid - 1 38 | else: 39 | low = mid + 1 40 | 41 | print(bag) -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 2/bubbleSortAlgorithmExample.py: -------------------------------------------------------------------------------- 1 | #Bubble Sort Algorithm: to sort the elements either in ascending or descending order. 2 | #definition- it is simpel algorithm that works by repeatedly swaping adjacent elements. If they are in wrong order. 3 | #Ascending: Greater element will bubble up to its correct position 4 | #Descending:Smaller element will bubble up to its correct position 5 | 6 | 7 | #How does it work? - Ascending Order 8 | #1. Initial Setup - Start with entire list as unsorted 9 | #2. Swap with Adjacent Element: It will swap adjacent element if they in wrong order[ascending: if element is greater than adjacent element then swap, descending: if element is greater than adjacent element then swap] 10 | #3. Repeat: In Each pass, you will able to shift larger element at last, keep repeating above process until the list is sorted. 11 | 12 | """ 13 | Example - Ascending Order 14 | list = [5,0,6,2,3,1] 15 | First Pass: [0,5,2,3,1,6] 16 | Second Pass: [0,2,3,1,5,6] 17 | Third Pass:[0,2,1,3,5,6] 18 | Fourth Pass:[0,1,2,3,5,6] 19 | 20 | list = [6,4,2,8,9,7,0] 21 | First Pass: [4,2,6,8,7,0,9] n-1 22 | Second Pass: [2,4,6,7,0,8,9] n-2 23 | Third Pass: [2,4,6,0,7,8,9] n-3 24 | Fourth Pass: [2,4,0,6,7,8,9] n-4 25 | Fifth Pass: [2,0,4,6,7,8,9] n-5 26 | Sixth Pass: [0,2,4,6,7,8,9] n-6 27 | 28 | 29 | Code: 30 | list = [6,4,2,8,9,7,0] 31 | for i in range(len(list)): 32 | for j in range(len(list)-i-1): 33 | if list[j] > list[j+1]: 34 | list[j], list[j+1] = list[j+1], list[j] 35 | 36 | Visualization: 37 | Round 1 : i = 0 38 | j = 0 , j<6 39 | [4,2,6,8,7,0,9] - n-1 40 | Round 2: i = 1 41 | j = 0, j<5 42 | [2,4,6,7,0,8,9] - n-2 43 | Round 3: i = 2 44 | j = 0, j<4 45 | [2,4,6,0,7,8,9] - n-3 46 | Round 4: i = 3 47 | j = 0, j<3 48 | [2,4,0,6,7,8,9] - n-4 49 | Round 5: i = 4 50 | j = 0, j<2 51 | [2,0,4,6,7,8,9] - n-5 52 | Round 6: i = 5 53 | j = 0, j<1 54 | [0,2,4,6,7,8,9] - n-6 55 | 56 | """ 57 | 58 | list = [6,4,2,8,9,7,0] 59 | 60 | #Ascending Order 61 | 62 | # print(f"Before Sorting: {list}") 63 | 64 | # for i in range(len(list)): 65 | # for j in range(len(list)-i-1): 66 | # if list[j] > list[j+1]: 67 | # list[j], list[j+1] = list[j+1], list[j] 68 | 69 | 70 | # print(f"After Sorting: {list}") 71 | 72 | 73 | #Descending Order 74 | 75 | print(f"Before Sorting: {list}") 76 | 77 | for i in range(len(list)): 78 | for j in range(len(list)-i-1): 79 | if list[j] < list[j+1]: 80 | list[j], list[j+1] = list[j+1], list[j] 81 | 82 | 83 | print(f"After Sorting: {list}") -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 2/introductionToSearchingAlgorithm.py: -------------------------------------------------------------------------------- 1 | #Searching Algorithm: It is used to search particular element in the list, this is most fundamental technique to search anything in computer science. 2 | 3 | 4 | 5 | #There are following Searching Algorithms: 6 | #1. Linear Search(Sequential Search) 7 | #2. Binary Search Algorithm 8 | #3. BFS 9 | #4. DFS 10 | #5. Others ... 11 | 12 | -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 2/linearSearchAlgorithmExample.py: -------------------------------------------------------------------------------- 1 | #Linear(Sequential) Search: it is simple algorithm that sequentially checks every element in the list, if element matches with target element then it returns/prints that element, if it reaches at end of list/not found, then you can return appropriate msg. 2 | 3 | 4 | #How does it work? 5 | #1. Initial Setup: Start with sorted and unsorted list. 6 | #2. Compare with Target Element: It compares with each element in sequence if any element matches with target element then it returns that element otherwise it returns some other msg. 7 | 8 | 9 | """ 10 | Example: 11 | 12 | Analogy 1 13 | list = [1,23,4,6,7,3,8,10] 14 | target = 7 15 | Round 1: goto to 1 and compare target == list[0] 16 | Round 2: goto to 23 and compare target == list[1] 17 | Round 3: goto to 4 and compare target == list[2] 18 | Round 4: goto to 6 and compare target == list[3] 19 | Round 5: goto to 7 and compare target == list[4] - return index 20 | 21 | Analogy 2 22 | list = [1,23,4,6,7,3,8,10] 23 | target = 11 24 | Round 1: goto to 1 and compare target == list[0] 25 | Round 2: goto to 23 and compare target == list[1] 26 | Round 3: goto to 4 and compare target == list[2] 27 | Round 4: goto to 6 and compare target == list[3] 28 | Round 5: goto to 7 and compare target == list[4] 29 | Round 6: goto to 3 and compare target == list[5] 30 | Round 7: goto to 8 and compare target == list[6] 31 | Round 7: goto to 10 and compare target == list[7] 32 | 33 | at last you can return msg - "not found", "-1", False 34 | 35 | """ 36 | 37 | 38 | #Example 1: consider below list, and create function that takes list and target element and returns the arget element index, if its not found then return -1 39 | # list = [1,23,4,6,7,3,8,10] 40 | # target = 11 41 | 42 | 43 | # def linearSearch(list, target): 44 | # for i in range(len(list)): 45 | # if list[i] == target: 46 | # return i 47 | # return -1 48 | 49 | # print(linearSearch(list, target)) 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 3/data.txt: -------------------------------------------------------------------------------- 1 | Delhi University -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 3/fileHandlingExample.py: -------------------------------------------------------------------------------- 1 | #Opening and Closing Files 2 | #To open the file - open(filePath, mode) 3 | #Important Modes: r(reading), w(writing), a(appending) 4 | #To Close the file - fileName.close() 5 | 6 | 7 | #Mode: 'r'(reading mode) - it opens with file only for reading, if the file doesn't exist then it will give error FileNotFoundError. 8 | 9 | #Note: it doesn't erase(clear) the file existing data at the time opening. 10 | 11 | # file = open('note.txt', 'r') 12 | # #print(file) #<_io.TextIOWrapper name='note.txt' mode='r' encoding='cp1252'> 13 | # #Reading the file - using fileVariableName.read() 14 | # print(file.read()) 15 | 16 | # #Write the file - using fileVariableName.write('Data') 17 | # file.write("Data is complex") #io.UnsupportedOperation: not writable 18 | # file.close() 19 | 20 | 21 | #Mode: 'w'(writing mode) - it opens with file only for writing, if the file doesn't exist then it creates the file instead of giving error. 22 | 23 | #Note: it erases(clears) the file existing data at the time of opening. 24 | 25 | # file = open('data.txt', 'w') - once this file named data.txt was not there then it create this file at time of opening. 26 | 27 | # file = open('note.txt', 'w') 28 | # #print(file.read()) #io.UnsupportedOperation: not readable 29 | # file.write("Hello World") 30 | # file.close() 31 | 32 | 33 | #Mode: 'a'(appending/merging mode mode) - it opens with file only for appending(adding the data to existing file), if the file doesn't exist then it creates the file instead of giving error. 34 | 35 | #Note: it doesn't erase(clear) the file existing data at the time of opening. 36 | 37 | # file = open('note.txt', 'a') 38 | #print(file.read()) #io.UnsupportedOperation: not readable 39 | # file.write("\nLearning Python From Chitkara") 40 | # file.write("\nDoing Everyday Practice") 41 | 42 | 43 | #Example: Read File which has below data mentioned below: 44 | """ 45 | note.txt 46 | Hello World 47 | Learning Python From Chitkara 48 | Doing Everyday Practice 49 | """ 50 | #Your task is to read the data line by line 51 | 52 | #Solution 53 | #Note: to read the data line by line - fileVariableName.readline() 54 | 55 | file = open('note.txt', 'r') 56 | # print(file.readline()) #first line in the file 57 | # print(file.readline()) #second line in the file 58 | 59 | # print(file.readline()) #third line in the file 60 | 61 | #To read all lines at once: 62 | # print(file.readlines()) 63 | 64 | # for data in file: 65 | # print(data) 66 | 67 | 68 | #Example 2: Given below file with data. 69 | """ 70 | data.txt 71 | Chitkara University 72 | """ 73 | #Your task is to convert Chitkara with Delhi 74 | 75 | # fileReading = open('data.txt', 'r') 76 | # data = fileReading.read() 77 | # print(data) 78 | # replacedData = data.replace("Chitkara", "Delhi") 79 | # print(replacedData) 80 | # fileReading.close() 81 | 82 | 83 | # fileWriting = open('data.txt', 'w') 84 | # fileWriting.write(replacedData) 85 | #fileWriting.close() 86 | 87 | 88 | #Example 2: Given below file with data. 89 | """ 90 | data.txt 91 | I am learning Java From Chitkara University 92 | Java is easy to learn 93 | """ 94 | #Your task is to replace Java with Python 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 3/note.txt: -------------------------------------------------------------------------------- 1 | Hello World 2 | Learning Python From Chitkara 3 | Doing Everyday Practice -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 3/uniqueIdGenerationExample.py: -------------------------------------------------------------------------------- 1 | import uuid 2 | 3 | #To Generate Unique id in string 4 | #print("".join(str(uuid.uuid4()).split("-"))) 5 | 6 | 7 | #To Generate Unique Id in Integer 8 | 9 | 10 | # print(str(uuid.uuid4().int)[:10:]) 11 | 12 | 13 | import time 14 | 15 | # print(time.ctime()) 16 | print(int(time.time()*1000)) 17 | 18 | -------------------------------------------------------------------------------- /Unit 3/Sprint 4/Day 3/whyFileHandlingInPython.py: -------------------------------------------------------------------------------- 1 | #Why File Handling in Python? 2 | #Reason 1: To interact with files stored in your computer, using this, we can easily perform operation on files such as reading, writing and modifing the data. 3 | 4 | #Reason 2: If you store the data in the file then there will no chances to delete. 5 | #Application - Student Registration System. 6 | import uuid 7 | 8 | studentsList = [] 9 | 10 | def menu(): 11 | print("1. Add Student") 12 | print("2. Get Students By Id") 13 | print("3. Get All Students") 14 | print("4. Update Student By Id") 15 | print("5. Delete Students By Id") 16 | print("6. Exit") 17 | 18 | def addStudent(): 19 | student = {} 20 | student["id"] = str(uuid.uuid4().int)[:15:] 21 | student["name"] = input("Enter Student Name: ") 22 | student["city"] = input("Enter Student City: ") 23 | student["marks"] = input("Enter Student Marks: ") 24 | studentsList.append(student) 25 | print("Student has registered successfully.") 26 | 27 | def getStudentById(): 28 | pass 29 | 30 | def getAllStudents(): 31 | for student in studentsList: 32 | print("======================================") 33 | print(f"Student Id: {student["id"]}") 34 | print(f"Student Name: {student["name"]}") 35 | print(f"Student City: {student["city"]}") 36 | print(f"Student Marks: {student["marks"]}") 37 | print("======================================") 38 | 39 | def updateStudentById(): 40 | pass 41 | 42 | def deleteStudentById(): 43 | pass 44 | 45 | while True: 46 | menu() 47 | choice = int(input("Enter Your Choice: ")) 48 | 49 | if choice == 1: 50 | addStudent() 51 | elif choice == 2: 52 | getStudentById() 53 | elif choice == 3: 54 | getAllStudents() 55 | elif choice == 4: 56 | updateStudentById() 57 | elif choice == 5: 58 | deleteStudentById() 59 | elif choice == 6: 60 | res = input("Do you want to exit(n/y): ") 61 | if res in ["y", "Y"]: 62 | print("Thank you using my application.") 63 | break 64 | else: 65 | print("Invalid Choice, Please Try Again.") 66 | -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 1/data.txt: -------------------------------------------------------------------------------- 1 | ["Chaman", "Rohan", "Sunil", "Pankaj", "Chinki"] -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 1/data1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitcodingrank/Python-G34/f3150173e7f1c6df78216fe78ebb92d205d5e863/Unit 4/Sprint 1/Day 1/data1.txt -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 1/moreAboutFilesExample.py: -------------------------------------------------------------------------------- 1 | #Till now, you all know, how to open file with modes - r, w, and a 2 | #you all know about closing of file. 3 | 4 | 5 | #Assignment Problems: 6 | #Problem 1: 7 | 8 | # list = ["Chaman", "Pawan", "Rohan", "Chunnu", "Munnu"] 9 | 10 | # writeFile = open('students.txt', 'w') 11 | # for i in range(len(list)): 12 | # if i==0: 13 | # writeFile.write(list[i]) 14 | # else: 15 | # writeFile.write("\n"+list[i]) 16 | # writeFile.close() 17 | 18 | # readFile = open('students.txt', 'r') 19 | # for name in readFile: 20 | # print(name.strip()) 21 | 22 | # while True: 23 | # line = readFile.readline() 24 | # if not line: 25 | # break 26 | # print(line.strip()) 27 | 28 | # allLines = readFile.readlines() 29 | # print(len(allLines)) 30 | #readFile.close() 31 | 32 | # wordList = readFile.read().splitlines() 33 | # print(wordList) 34 | 35 | # #Freequency: 36 | # print({word:wordList.count(word) for word in set(wordList)}) 37 | 38 | 39 | #Cursor Positioning in File: 40 | #tell() - tells the position of cursor 41 | #seek(n) - it changes the cursor position 42 | 43 | #Note: on writing and reading your cursor postion gets changed. 44 | 45 | # file = open('data.txt', 'r') 46 | # print(file.tell())#0 47 | # print(file.read())#Students are okay 48 | # print(file.tell())#17 49 | # print(file.read()) 50 | # file.seek(0) 51 | # print(file.tell())#0 52 | # print(file.read()) 53 | # print(file.tell()) 54 | # file.close() 55 | 56 | # file = open('data.txt', 'a') 57 | # print(file.tell()) 58 | # file.seek(0) 59 | # file.write("Chitkara") 60 | 61 | #Advance Modes: 'r+' - opened the file for both reading and writing, and if file doesn't exist then it gives error: FileNotFoundError 62 | 63 | #Note: it doesn't truncate(clear) the file data on opening the file. 64 | #Note: in this case cursor points in the beginning of file. 65 | 66 | # file = open('data.txt', 'r+') 67 | # print(file.tell())#0 68 | # print(file.read())#readig 69 | # print(file.tell()) 70 | # file.write("Chitkara")#writing 71 | # file.seek(0) 72 | # file.write("Chaman") 73 | # print(file.tell()) 74 | # file.truncate() 75 | #file.close() 76 | 77 | 78 | #Advance Modes: 'w+' - opened the file for both reading and writing, and if file doesn't exist then it creates the file 79 | 80 | #Note: it truncates(clears) the file data on opening the file. 81 | #Note: in this case cursor points in the beginning of file. 82 | 83 | # file = open('data.txt', 'w+') 84 | # print(file.tell())#0 85 | # file.write("Hello Everyone") 86 | # print(file.tell())#14 87 | # print(file.read()) 88 | # file.seek(0) 89 | # print(file.read()) 90 | #file.close() 91 | 92 | 93 | #Advance Modes: 'a+' - opened the file for both reading and writing, and if file doesn't exist then it creates the file 94 | 95 | #Note: it doesn't truncate(clear) the file data on opening the file. 96 | #Note: in this case cursor points at end of file. 97 | 98 | # file = open('data.txt', 'a+') 99 | # print(file.tell())#14 100 | # print(file.read()) 101 | # file.seek(0) 102 | # print(file.read()) 103 | # print(file.tell()) 104 | # file.seek(0) 105 | # file.write('Something Went Wrong') 106 | 107 | 108 | #Examples: Add list of students to students.txt file and add one more student to it. 109 | 110 | import json 111 | 112 | students = ["Chaman", "Rohan", "Sunil", "Pankaj"] 113 | 114 | file = open('data.txt', 'r+') 115 | #file.write(students) #TypeError: write() argument must be str, not list 116 | 117 | #Wthout JSON 118 | # file.write(" ".join(students)) 119 | # file.truncate() 120 | # studentStr = file.read() 121 | # studentsList = studentStr.split() 122 | # studentsList.append("Chinki") 123 | # # print(studentsList) 124 | 125 | # file.seek(0) 126 | # file.write(" ".join(studentsList)) 127 | # file.truncate() 128 | 129 | #With the help of JSON 130 | # file.write(json.dumps(students)) 131 | 132 | #add another sutdents 133 | # studentList = json.loads(file.read()) 134 | # studentList.append("Chinki") 135 | # file.seek(0) 136 | # file.write(json.dumps(studentList)) 137 | # file.truncate() 138 | 139 | 140 | -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 1/students.txt: -------------------------------------------------------------------------------- 1 | Chaman 2 | Pawan 3 | Rohan 4 | Chunnu 5 | Munnu 6 | Munnu -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 2/fileRecap.py: -------------------------------------------------------------------------------- 1 | #What are the important step in every mode? - file opening and closing 2 | 3 | # file = open('students.json', 'r') 4 | # print(file.read()) 5 | # file.close() 6 | 7 | 8 | # #modern way to open the file and in this way python automatically close the file if it is no longer needed. 9 | 10 | # with open('students.json', 'r+') as file: 11 | # print(file.read()) 12 | # file.write("Hello Everyone") 13 | 14 | 15 | #Good Example: given students.json file, your task is to read and write the data. 16 | import json 17 | 18 | def addStudent(student): 19 | with open('students.json', 'r+') as file: 20 | studentData = json.loads(file.read()) 21 | 22 | studentData["students"].append(student) 23 | print(studentData) 24 | file.seek(0) 25 | file.write(json.dumps(studentData)) 26 | file.truncate() 27 | 28 | addStudent({"name":"Chaman", "age":34, "city":"Delhi"}) 29 | -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 2/introductionToObjectOrientedProgramming.py: -------------------------------------------------------------------------------- 1 | #Note: Python supports various kind of programming paradigm(the way/style of writing code). 2 | 3 | #There are following types of programming paradigm: 4 | #1. Procedural programming [Done] 5 | #2. Functional Programming [Done] 6 | #3. Object Oriented Programming [Pending] 7 | 8 | #Why Object Oriented Programming? 9 | #Note: in object oriented programming everything is object or you can say object is first citizen. 10 | 11 | #Reason: In real world, everything is object, and in each object two things are common. 12 | #1. how they look/state/property 13 | #2. how they act/behavior/functionality 14 | 15 | """ 16 | Examples: 17 | Mobile: Object 18 | 1. how they look/state/property 19 | brandName 20 | model 21 | backCamera 22 | frontCamera 23 | bettery 24 | color 25 | 2. how they act/behavior/functionality 26 | playMusic 27 | pauseMusic 28 | playVideo 29 | doVideoCall 30 | audioCall 31 | doMsg 32 | Bike: Object 33 | 1. how they look/state/property 34 | model 35 | brand 36 | wheels 37 | 2. how they act/behavior/functionality 38 | move 39 | brake 40 | increase speed 41 | 42 | Technically - how they look/state/property - state/variable/property 43 | Technically - how they act/behave/functionality - functionality/method/behavior 44 | 45 | Before object Oriented programming, we're having to write these two(state and behavior)things sepereatly 46 | 47 | """ 48 | 49 | 50 | #Before Object Oriented Programming Example: 51 | 52 | #Account: Object 53 | 54 | #Functions/behaviors/acts 55 | 56 | def depositMoney(accountNumber, availBalance, amount): 57 | pass 58 | 59 | def withdrawalMoney(accountNumber, availBalance, amount): 60 | pass 61 | 62 | def checkBalance(accountNumber, availBalance, amount): 63 | pass 64 | 65 | 66 | #States/Properties/looks 67 | accountNumber = "123456789" 68 | availableBalance = 5000 69 | 70 | 71 | #According to above example, in this case your code follows following things: 72 | #redudancy/duplicay 73 | #less secure data 74 | #there is no modelarity 75 | 76 | 77 | #With the help object oriented programming, we bind these two important things about object as single entity. 78 | 79 | -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 2/studentRegistrationSystem.py: -------------------------------------------------------------------------------- 1 | import uuid 2 | import json 3 | 4 | def addStudentToFile(student): 5 | with open('students.json', 'r+') as file: 6 | studentData = json.loads(file.read()) 7 | 8 | studentData["students"].append(student) 9 | print(studentData) 10 | file.seek(0) 11 | file.write(json.dumps(studentData)) 12 | file.truncate() 13 | 14 | def getStudentsFromFile(): 15 | with open('students.json', 'r') as file: 16 | studentData = json.loads(file.read()) 17 | return studentData["students"] 18 | 19 | 20 | def menu(): 21 | print("1. Add Student") 22 | print("2. Get Students By Id") 23 | print("3. Get All Students") 24 | print("4. Update Student By Id") 25 | print("5. Delete Students By Id") 26 | print("6. Exit") 27 | 28 | def addStudent(): 29 | student = {} 30 | student["id"] = str(uuid.uuid4().int)[:15:] 31 | student["name"] = input("Enter Student Name: ") 32 | student["city"] = input("Enter Student City: ") 33 | student["marks"] = input("Enter Student Marks: ") 34 | addStudentToFile(student) 35 | print("Student has registered successfully.") 36 | 37 | def getStudentById(): 38 | pass 39 | 40 | def getAllStudents(): 41 | for student in getStudentsFromFile(): 42 | print("======================================") 43 | print(f"Student Id: {student["id"]}") 44 | print(f"Student Name: {student["name"]}") 45 | print(f"Student City: {student["city"]}") 46 | print(f"Student Marks: {student["marks"]}") 47 | print("======================================") 48 | 49 | def updateStudentById(): 50 | pass 51 | 52 | def deleteStudentById(): 53 | pass 54 | 55 | while True: 56 | menu() 57 | choice = int(input("Enter Your Choice: ")) 58 | 59 | if choice == 1: 60 | addStudent() 61 | elif choice == 2: 62 | getStudentById() 63 | elif choice == 3: 64 | getAllStudents() 65 | elif choice == 4: 66 | updateStudentById() 67 | elif choice == 5: 68 | deleteStudentById() 69 | elif choice == 6: 70 | res = input("Do you want to exit(n/y): ") 71 | if res in ["y", "Y"]: 72 | print("Thank you using my application.") 73 | break 74 | else: 75 | print("Invalid Choice, Please Try Again.") -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 2/students.json: -------------------------------------------------------------------------------- 1 | { 2 | "students": [ 3 | { 4 | "id": "819427494836468", 5 | "name": "Chintu", 6 | "city": "Noida", 7 | "marks": "432" 8 | }, 9 | { 10 | "id": "971455340664296", 11 | "name": "Bimal", 12 | "city": "Ghaziabad", 13 | "marks": "563" 14 | }, 15 | { 16 | "id": "198146814681126", 17 | "name": "Chirag", 18 | "city": "NOida", 19 | "marks": "453" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 3/moreAboutObjectOrientedProgrammingExample.py: -------------------------------------------------------------------------------- 1 | #Object Oriented Programming: It is most popular programming paradigm where object is the first citizen. 2 | #In other word: With the help of object, you can solve any problem. 3 | 4 | #Benifit of Object Oriented Programming: 5 | #1. Reusability 6 | #2. Stratured/Modularity 7 | #3. Data Security/Hiding 8 | #4. Abstraction 9 | 10 | #Pillars of Object Oriented Programming: 11 | #1. class 12 | #2. object 13 | #3. Encapsulation 14 | #4. Inheritance 15 | #5. Polymorphism 16 | #6. Abstraction 17 | 18 | 19 | #1. class - it is a blueprint/structure for creating the objects. 20 | #Note: you can create class using 'class' keyword, and always give the name of the class in PascalCaseNamingConvetion. 21 | 22 | """ 23 | synatax: 24 | class ClassName: 25 | #class body 26 | """ 27 | 28 | class Mobile: 29 | #properties 30 | #behaviors 31 | pass 32 | 33 | #Note: in a class, there are two types of methods, and attribute/variables/states/properties 34 | 35 | #Methods: 36 | #1. static/class method 37 | #2. non static/instance method 38 | 39 | #States/Propeties/Variables/Attributes 40 | #1. static/class attributes/variables 41 | #2. non static/instance attributes/variables 42 | 43 | #Example of static variables/Attributes and methods/behaviors 44 | 45 | 46 | # class Maths: 47 | # #static/class variable/attribute 48 | # pi = 3.14 49 | 50 | # #static methods/behaviors 51 | # @staticmethod 52 | # def findRectangleArea(length, width): 53 | # return length * width 54 | 55 | # @staticmethod 56 | # def welcome(name): 57 | # return f"welcome {name}" 58 | 59 | #Note: how to access the static variable and method of the class? 60 | #Answer: you can access either using class name or using class object. 61 | 62 | # print(Maths.pi) 63 | # print(Maths.findRectangleArea(20,10)) 64 | # print(Maths.welcome('Rakesh')) 65 | 66 | 67 | #non static/instance variables/methods 68 | #Note: to define instance attributes/variables, you need to use constructor function. 69 | 70 | # class Maths: 71 | # #static/class variable/attribute 72 | # pi = 3.14 73 | 74 | # def __init__(self, name): 75 | # #instance variable/attribute/state 76 | # self.name = name 77 | 78 | # #static methods/behaviors 79 | # @staticmethod 80 | # def findRectangleArea(length, width): 81 | # return length * width 82 | 83 | # #instance/non-static method 84 | # def welcome(name): 85 | # return f"welcome {name}" 86 | 87 | #Note: to access instance/non-static varibales/methods, you need to create the object. 88 | 89 | #Without object 90 | #print(Maths.name) #AttributeError: type object 'Maths' has no attribute 'name' 91 | 92 | 93 | #Object: instance/reference of class which has methods(behaviors) and attribtues(states/properties) 94 | #you can create n number of object of a class. 95 | 96 | """ 97 | how to create object? 98 | syntax: 99 | 100 | object/instance= ClassName() 101 | """ 102 | 103 | #Note: at the time of creating the class object, class constructor function automatically get called. 104 | 105 | # class Maths: 106 | # #static/class variable/attribute 107 | # pi = 3.14 108 | 109 | # def __init__(self, name): 110 | # #instance variable/attribute/state 111 | # self.name = name 112 | 113 | # #static methods/behaviors 114 | # @staticmethod 115 | # def findRectangleArea(length, width): 116 | # return length * width 117 | 118 | # #instance/non-static method 119 | # def welcome(self): 120 | # return f"welcome {self.name}" 121 | 122 | # def __str__(self): 123 | # return f"Name is {self.name}" 124 | 125 | # obj1 = Maths("Rakesh") 126 | #print(obj1) #<__main__.Maths object at 0x000002810AF66270> 127 | 128 | #Note: i don't want object to return this <__main__.Maths object at 0x000002810AF66270> instead i want it to print whatever i want. 129 | #Note: to do this you need to override one internal method def__str__() 130 | 131 | #After overriding the __str__ method 132 | # print(obj1) 133 | # print(obj1.name) 134 | # print(obj1.welcome()) 135 | # obj2 = Maths() 136 | 137 | #Constructor Function: it helps to create the object of the class. 138 | # you can define one constructor one class 139 | # At the time of creating class object, given constructor function gets called, if constructor function is not given then defualt constructor gets called by python internally. 140 | #default constructor: def __init__() 141 | #It is mendatory to have constructor function in class 142 | 143 | #Example: 144 | 145 | # class Student: 146 | # #static/class Attribute/variabels 147 | # univerisity = "Chitkara" 148 | # universityAddress = "Rajpura Road, Punjab" 149 | 150 | # def __init__(self, name, age, city): 151 | # self.name = name 152 | # self.age = age 153 | # self.city = city 154 | 155 | # def __str__(self): 156 | # return f"Name: {self.name}, Age: {self.age}, City: {self.city}" 157 | 158 | 159 | # student1 = Student("Rakesh", 34, "Noida") 160 | # #print(student1)#<__main__.Student object at 0x000001FC84B86090> 161 | 162 | # #First Way 163 | # # print(student1.name) 164 | # # print(student1.age) 165 | # # print(student1.city) 166 | 167 | # print(student1) 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /Unit 4/Sprint 1/Day 4/moreAboutObjectOrientedProgrammingExample.py: -------------------------------------------------------------------------------- 1 | #Till now in Object Oriented Programming: 2 | """ 3 | Introduction to OOPS 4 | Why OOPS 5 | Features 6 | Class 7 | Object 8 | static/non static attributes/methods 9 | """ 10 | 11 | #Example: Given Student class with instance attributes - name, city, marks. Kindly create 5 different student class object. 12 | 13 | # class Student: 14 | 15 | # def __init__(self, name, city, marks): 16 | # self.studentName = name 17 | # self.studentCity = city 18 | # self.studentMarks = marks 19 | 20 | # def __str__(self): 21 | # return str({"name":self.studentName, "city":self.studentCity, "marks":self.studentMarks}) 22 | 23 | # #Asked to create 5 different object of the class? 24 | # student1 = Student('Rakesh', "Noida", 456) 25 | # student2 = Student('Prem', "Delhi", 156) 26 | # student3 = Student('Sonal', "Haryana", 343) 27 | # student4 = Student('Rohan', "Chandigarh", 453) 28 | # student5 = Student('Raman', "Rajpura", 346) 29 | 30 | # # print(student1.studentName) 31 | # # print(student3.studentCity) 32 | 33 | # studentList = [student1, student2, student3, student4, student5] 34 | 35 | # #print every student name in seperate line 36 | # # for student in studentList: 37 | # # print(student.studentName) 38 | 39 | 40 | # for student in studentList: 41 | # print(student) 42 | 43 | 44 | #Rest Oops Pillars: 45 | 46 | #Encapsulation: 47 | #Why Encapsulation - 48 | 49 | # class Student: 50 | # #Class Variable - class/object to accesss 51 | # university = "Chitkara" 52 | # def __init__(self, name, city, marks): 53 | # #Instance Variable - Need object to access 54 | # self.studentName = name 55 | # self.studentCity = city 56 | # self.studentMarks = marks 57 | 58 | 59 | # def __str__(self): 60 | # return f"Name: {self.studentName}, City: {self.studentCity}, Marks: {self.studentMarks}" 61 | 62 | # student1 = Student('Rakesh', "Noida", 456) 63 | # print(student1.studentMarks) 64 | # print(student1.university) 65 | 66 | 67 | # class User: 68 | # def __init__(self, name): 69 | # self.name = name 70 | # self.loginStatus = False 71 | 72 | # def verifyEmail(self, email): 73 | # #perform validation logic 74 | # return True 75 | 76 | # def verifyPassword(self, password): 77 | # #perform validation logic 78 | # return True 79 | 80 | # def login(self, email, password): 81 | # isVerified = False 82 | # isVerified = self.verifyEmail(email) and self.verifyPassword(password) 83 | 84 | # if isVerified: 85 | # self.email = email 86 | # self.password = password 87 | # self.loginStatus = True 88 | # print("Logged in Successfully.") 89 | # else: 90 | # print("Invalid Credentials, Please try again.") 91 | 92 | 93 | # user1 = User('Prakash') 94 | 95 | # # print(user1.name) 96 | # # print(user1.email) 97 | # # user1.login("prakash@gmail.com", "12345") 98 | # # print(user1.email) 99 | # # print(user1.password) 100 | 101 | # print(user1.verifyEmail("prakash@gmail.com")) 102 | 103 | 104 | #According to above example, class data is not secure anyone can access it outside the class. 105 | 106 | #Encapsulation: Making all the methods and attribute as private so that outside the class none can access it. 107 | 108 | #How to make methods and variables as private: 109 | #Syntax: __variable/methodName 110 | 111 | 112 | # class User: 113 | # def __init__(self, name): 114 | # self.__name = name #private attribute/variables 115 | # self.__loginStatus = False #private attribute/variables 116 | 117 | # def __verifyEmail(self, email): #private method 118 | # #perform validation logic 119 | # return True 120 | 121 | # def __verifyPassword(self, password): #private method 122 | # #perform validation logic 123 | # return True 124 | 125 | # def login(self, email, password): 126 | # isVerified = False 127 | # isVerified = self.__verifyEmail(email) and self.__verifyPassword(password) 128 | 129 | # if isVerified: 130 | # self.__email = email 131 | # self.__password = password 132 | # self.__loginStatus = True 133 | # print("Logged in Successfully.") 134 | # else: 135 | # print("Invalid Credentials, Please try again.") 136 | 137 | # def logout(self): 138 | # self.__loginStatus=False 139 | # print("Logged out successfully") 140 | 141 | # def printDetails(self): 142 | # if self.__loginStatus: 143 | # return f"Name: {self.__name}, Email: {self.__email}" 144 | # else: 145 | # return "You're logged out, Please login again." 146 | 147 | 148 | # user1 = User('Prakash') 149 | 150 | # print(user1.name) 151 | # print(user1.email) 152 | # user1.login("prakash@gmail.com", "12345") 153 | # print(user1.email) 154 | # print(user1.password) 155 | 156 | #print(user1.__verifyEmail("prakash@gmail.com")) #AttributeError - has no attribute as __verifyEmail 157 | 158 | #print(user1.__name) #AttributeError - has no attribute as __name 159 | # user1.login("prakash@gmail.com", "12345") 160 | # print(user1.printDetails()) 161 | # user1.logout() 162 | 163 | # print(user1.printDetails()) 164 | 165 | #In above example, anyhow we're anle to mantain the encapsulation by making attributes and methods as private, but still it is not fully encapsulated class because you're not able to access the private variable as well as not able to change the variable data. 166 | 167 | #Fully Encapsulated class follows: 168 | #1. all the methods and attributes of the class must be private. 169 | #1. it must have getter and setter method to get and update the value of the attributes. 170 | 171 | # class User: 172 | # def __init__(self, name): 173 | # self.__name = name #private attribute/variables 174 | # self.__loginStatus = False #private attribute/variables 175 | 176 | # def __verifyEmail(self, email): #private method 177 | # #perform validation logic 178 | # return True 179 | 180 | # def __verifyPassword(self, password): #private method 181 | # #perform validation logic 182 | # return True 183 | 184 | # def login(self, email, password): 185 | # isVerified = False 186 | # isVerified = self.__verifyEmail(email) and self.__verifyPassword(password) 187 | 188 | # if isVerified: 189 | # self.__email = email 190 | # self.__password = password 191 | # self.__loginStatus = True 192 | # print("Logged in Successfully.") 193 | # else: 194 | # print("Invalid Credentials, Please try again.") 195 | 196 | # def logout(self): 197 | # self.__loginStatus=False 198 | # print("Logged out successfully") 199 | 200 | # def printDetails(self): 201 | # if self.__loginStatus: 202 | # return f"Name: {self.__name}, Email: {self.__email}" 203 | # else: 204 | # return "You're logged out, Please login again." 205 | 206 | # #Getter methods - to get the value 207 | # def getName(self): 208 | # return self.__name 209 | 210 | # def getEmail(self): 211 | # return self.__email 212 | 213 | # #Setter method - to set/update the value 214 | 215 | # def setName(self, name): 216 | # self.__name = name 217 | 218 | # def setEmail(self, email): 219 | # self.__email = email 220 | 221 | 222 | # user1 = User('rohan') 223 | # user1.login('rohan@gmail.com', '12345') 224 | # # print(user1.printDetails()) 225 | 226 | # # print(user1.getEmail()) 227 | # # user1.setEmail('random@gmail.com') 228 | # # print(user1.getEmail()) 229 | 230 | # user2 = User('admin') 231 | 232 | # user2.login('admin', 'admin') 233 | # print(user2.printDetails()) 234 | 235 | 236 | #4. Inheritance: in this a class can access the properties/methods of another class. 237 | #Note: rather than owning anything its better to owe. 238 | 239 | """ 240 | Cat Family - Tiger, Lion 241 | 242 | Cat properties: 243 | fur = True 244 | jump = True 245 | tail = True 246 | legs = 4 247 | - other 20 properties 248 | 249 | methods 250 | canJump() 251 | return True 252 | 253 | Tiger Properties: 254 | 255 | """ 256 | 257 | # class Cat: 258 | 259 | # #class properties - to access - class/object 260 | # jump =True 261 | # tail =True 262 | # fur = True 263 | # legs = 4 264 | 265 | # def __init__(self, name): 266 | # self.name = name 267 | 268 | 269 | # class Tiger(Cat): 270 | # pass 271 | 272 | # class Lion(Cat): 273 | # pass 274 | 275 | # cat = Cat('Cat') 276 | 277 | # print(cat.name) 278 | # print(cat.fur) 279 | # print(cat.jump) 280 | 281 | # print("--------------------") 282 | 283 | # tiger = Tiger('Tiger') 284 | 285 | # print(tiger.name) 286 | # print(tiger.fur) 287 | # print(tiger.jump) 288 | 289 | # print("--------------------") 290 | 291 | # lion = Lion('Lion') 292 | 293 | # print(lion.name) 294 | # print(lion.fur) 295 | # print(lion.jump) 296 | 297 | 298 | # class Person: 299 | # def __init__(self, name, city): 300 | # self.name = name 301 | # self.city = city 302 | 303 | # def printDetails(self): 304 | # print(f"Name: {self.name}, City: {self.city}") 305 | 306 | # class Employee(Person): 307 | # def __init__(self, name,city, salary): 308 | # super().__init__(name, city) 309 | # self.salary = salary 310 | 311 | # def printDetails(self): 312 | # super().printDetails() 313 | # print(f"Salary: {self.salary}") 314 | 315 | # employee = Employee('Rakesh', 'Noida', 50000) 316 | # employee.printDetails() 317 | 318 | #Polymorphism: As name suggest - poly - many and morphism - forms - in polymorphism, one method can perform different tasks according to the object. 319 | 320 | #There are two types of polymorphism: 321 | #1. method overloading - python doesn't support it. 322 | #2. method overriding - you can achieve using inheritance. 323 | 324 | ##1. method overloading - python doesn't support it, but some of the methods of python perform method overloading. 325 | 326 | #Example: 327 | 328 | # print(len([2,3,3,4,5])) # 5 329 | # print(len("chitkara")) # 8 330 | 331 | # class Maths: 332 | 333 | # @staticmethod 334 | # def sum(*args): 335 | # return sum(args) 336 | 337 | 338 | # print(Maths.sum(1,2,3,4,5)) 339 | # print(Maths.sum(1,2,3)) 340 | # print(Maths.sum(1,2)) 341 | 342 | #2. Method Overriding - you can achieve method overriding with the help of inheritance: 343 | 344 | 345 | # class Shape: 346 | # pi = 3.14 347 | # def area(self): 348 | # pass 349 | 350 | # class Rectangle(Shape): 351 | 352 | # def __init__(self, length, width): 353 | # self.length = length 354 | # self.width = width 355 | 356 | # #here you've overridden parent class method - method overrding. 357 | # def area(self): 358 | # return self.length * self.width 359 | 360 | # class Circle(Shape): 361 | 362 | # def __init__(self, radius): 363 | # self.radius = radius 364 | 365 | 366 | # #here you've overridden parent class method - method overrding. 367 | # def area(self): 368 | # return self.pi * (self.radius ** 2) 369 | 370 | 371 | # rectangle = Rectangle(10, 20) 372 | # print(rectangle.area()) 373 | 374 | # print("----------------------") 375 | 376 | # circle = Circle(10) 377 | # print(circle.area()) 378 | 379 | #Abstraction - it shows only the essential information to the user and hider complex implementation. 380 | #Example: Tv Remote, ATM 381 | 382 | #How to achieve Abstraction in Python - to achieve abstraction in python, we abstract class. 383 | 384 | #Abstract class: it is similar to other, but it also contains abstract method and you can't create the object of abstract class. 385 | 386 | #Note: to create the abstract in python you need to import abc module. 387 | 388 | 389 | from abc import ABC, abstractmethod 390 | 391 | class Vehicle(ABC): 392 | 393 | @abstractmethod 394 | def drive(self): 395 | pass 396 | 397 | vehicle = Vehicle()# TypeError: Can't instantiate abstract class Vehicle without an implementation for abstract method 'drive' 398 | 399 | -------------------------------------------------------------------------------- /Unit 4/Sprint 2/Day 1/data.txt: -------------------------------------------------------------------------------- 1 | Welcome to Chitkara University -------------------------------------------------------------------------------- /Unit 4/Sprint 2/Day 1/introductionToExceptionHandlingExample.py: -------------------------------------------------------------------------------- 1 | #Exception Handling: it is one of most critical part of every programming language that ensures your code to handle runtime errors gracefully without terminating your program. 2 | 3 | #Note: error always occurs on run-time. 4 | 5 | #Exception: An event that disrupts the normal flow of your program. 6 | 7 | #Why Exception Handling? 8 | #1. prevents abrupt termincation of your program. 9 | #2. on exception , you can give meaningful msg rather than stopping it. 10 | 11 | #Example: 12 | 13 | # print("Welcome to India") 14 | 15 | # print(4+4) 16 | 17 | # age = 45 18 | # print("Eligible" if age>=18 else "Not Eligible") 19 | 20 | # #Prime Number Logic 21 | 22 | # list = [1,2,3,4,5] 23 | # print(list[8]) #IndexError 24 | 25 | # print("Chlo Ghar Chle") 26 | 27 | # num = 3 28 | # count = 0 29 | # for i in range(1, num+1): 30 | # if num%i==0: 31 | # count+=1 32 | 33 | # if count ==2: 34 | # print("Prime") 35 | # else: 36 | # print("Not Prime") 37 | 38 | #1000 lines of code. 39 | 40 | # file = open('data.txt', 'r') 41 | 42 | 43 | #How to Handle the Exeption? 44 | 45 | """ 46 | to handle exception, we use try and except block. 47 | syntax: 48 | 49 | try: 50 | code that can have error 51 | except ErrorName: 52 | it handle the error when particular given error occurs. 53 | 54 | """ 55 | 56 | 57 | #Exmaple: 58 | 59 | # print("Welcome to Exception Handling") 60 | 61 | # try: 62 | # age 63 | # print(age) 64 | # except NameError: 65 | # print("Can't leave a variable with value") 66 | 67 | # print("Let's go to Chitkara University") 68 | 69 | 70 | #Example: 71 | 72 | 73 | # print("Welcome to Exception Handling") 74 | 75 | # try: 76 | # a = int(input("Enter Number 1: ")) 77 | # b = int(input("Enter Number 2: ")) 78 | 79 | # print(f"Addition is: {a+b}") 80 | 81 | # print(f"Division is: {a/b}") 82 | 83 | # except ValueError: 84 | # print("Please enter the valid number.") 85 | # except ZeroDivisionError: 86 | # print("A number can't divide by zero") 87 | 88 | # print("Let's go to Chitkara University") 89 | 90 | #Other Way for above program: 91 | 92 | # print("Welcome to Exception Handling") 93 | 94 | # try: 95 | # a = int(input("Enter Number 1: ")) 96 | # b = int(input("Enter Number 2: ")) 97 | 98 | # print(f"Addition is: {a+b}") 99 | 100 | # print(f"Division is: {a/b}") 101 | 102 | # except (ValueError, ZeroDivisionError) as e: 103 | # print(f"Error is: {e}") 104 | 105 | # print("Let's go to Chitkara University") 106 | 107 | 108 | #Third Way: 109 | 110 | # print("Welcome to Exception Handling") 111 | 112 | # try: 113 | # a = int(input("Enter Number 1: ")) 114 | # b = int(input("Enter Number 2: ")) 115 | 116 | # print(f"Addition is: {a+b}") 117 | 118 | # print(f"Division is: {a/b}") 119 | 120 | # except Exception as e: 121 | # print(f"Error is: {e}") 122 | 123 | # print("Let's go to Chitkara University") 124 | 125 | 126 | #Note: one try block can have more than one except block to handle the error gracefully and give the meaningful output to the user. 127 | 128 | #else, and finally block. 129 | #else: it runs when there is no error in the try block. 130 | 131 | #Example: 132 | 133 | # print("Welcome to Exception Handling") 134 | 135 | # try: 136 | # a = int(input("Enter Number 1: ")) 137 | # b = int(input("Enter Number 2: ")) 138 | 139 | # addition = a+b 140 | # division = a/b 141 | 142 | # except ValueError: 143 | # print("Please take valid Number.") 144 | # except ZeroDivisionError: 145 | # print("A number can't divide by zero") 146 | # else: 147 | # print(f"Division is: {division}") 148 | # print(f"Addition is: {addition}") 149 | 150 | 151 | 152 | 153 | # print("Let's go to Chitkara University") 154 | 155 | #finally: it executes every time where there is error or not error, it is used to close or stop the important resources: 156 | 157 | 158 | # print("Welcome to Exception Handling") 159 | 160 | # try: 161 | # file = open('data.txt', 'r') 162 | # print(file.read()) 163 | 164 | # except FileNotFoundError: 165 | # print("File doesn't exit, please create the file.") 166 | # else: 167 | # print("Inside else block") 168 | # finally: 169 | # try: 170 | # file.close() 171 | # except NameError: 172 | # print("file doesn't exist.") 173 | 174 | 175 | 176 | # print("Let's go to Chitkara University") 177 | 178 | 179 | 180 | #Problem: Create a program where you're taking input from the user to perform addition, substraction, mulitplication, and division, and also take care about errors, if any error occurs kindly handle it and give meaningful msg. 181 | 182 | 183 | # try: 184 | # a = int(input("Enter Number 1: ")) 185 | # b = int(input("Enter Number 2: ")) 186 | 187 | # addition = a+b 188 | # division = a/b 189 | # subtraction = a-b 190 | # multiplication = a-b 191 | 192 | # except ValueError: 193 | # print("Please take valid Number.") 194 | # except ZeroDivisionError: 195 | # print("A number can't divide by zero") 196 | # else: 197 | # print(f"Division is: {division}") 198 | # print(f"Addition is: {addition}") 199 | # print(f"Difference is: {subtraction}") 200 | # print(f"Product is: {multiplication}") 201 | 202 | 203 | #Problem 2: Create a program, where your task is to read the file and if file doesn't exist, create the file. 204 | 205 | # try: 206 | # file = open('data.txt', 'r') 207 | # print(file.read()) 208 | # except FileNotFoundError: 209 | # file = open('data.txt', 'w') 210 | # print("File has created.") 211 | # file.write('Welcome to Chitkara University') 212 | # print("Data has inserted.") 213 | # finally: 214 | # file.close() 215 | 216 | 217 | #How to raise exception? - using raise function. 218 | 219 | # try: 220 | # age = int(input("Enter Age: ")) 221 | 222 | # if age>=18: 223 | # print("permission granted.") 224 | # else: 225 | # raise ValueError('Age must be greater than or equal to 18') 226 | # except ValueError as e: 227 | # print(f"Error is {e}") 228 | 229 | 230 | #There are two types of exception: 231 | #1. inbuilt exception: examples above 232 | #Example: FileNotFoundError, NameError, ValueError, IndexError, KeyError, and so on. 233 | 234 | #2. Custom Exception - you can create your own exception as well. 235 | 236 | #Note: need to inheritate the exception class which is parent of all the clas. 237 | """ 238 | clas Excpetion: 239 | def __init__(self, message): 240 | self.message = message 241 | 242 | """ 243 | 244 | 245 | class AgeNotMatchedException(Exception): 246 | def __init__(self, message): 247 | super().__init__(message) 248 | 249 | class StudentNotFoundExeption(Exception): 250 | def __init__(self, message): 251 | super().__init__(message) 252 | 253 | # try: 254 | # age = int(input("Enter Age: ")) 255 | 256 | # if age>=18: 257 | # print("permission granted.") 258 | # else: 259 | # raise AgeNotMatchedException('Age must be greater than or equal to 18') 260 | # except AgeNotMatchedException as e: 261 | # print(f"Error is {e}") 262 | 263 | #Example 2: 264 | 265 | # try: 266 | # rollNumber = input("Enter Student RollNumber: ") 267 | 268 | # if rollNumber == "12345678": 269 | # print("Received Student Data.") 270 | # else: 271 | # raise StudentNotFoundExeption("Invalid Student Roll Number") 272 | # except StudentNotFoundExeption as e: 273 | # print(f"Error is {e}") 274 | 275 | 276 | #Problem: Create BookNotFoundException if the bookId is not matching with 12345 then raise this exception and give the meaninful msg. 277 | 278 | 279 | -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 1/LabelExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | 5 | #to make root window center: 6 | width = 800 7 | height = 500 8 | 9 | screenWidth = root.winfo_screenwidth() 10 | screenHeight = root.winfo_screenheight() 11 | 12 | x = int((screenWidth/2-width/2)) 13 | y = int((screenHeight/2-height/2)) 14 | root.geometry(f"{width}x{height}+{x}+{y}") 15 | 16 | #Label: to show the text related data. 17 | lb1 = Label(root, text="Welcome to TKINTER class", font=("Arial", 30, "bold"), fg="red", bg="yellow") 18 | 19 | #pack - to align the widget at specific place. 20 | # lb1.pack(side=TOP) 21 | #margin - padx - x axis, pady - y axis 22 | # lb1.pack(side=TOP, pady=30, padx=20) 23 | #padding - ipadx - x axis, ipady - y axis 24 | lb1.pack(side=TOP, pady=20, ipadx=50, ipady=20) 25 | #fill and expand 26 | 27 | #grid() 28 | #place() 29 | 30 | 31 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 1/introductionToTkinter.py: -------------------------------------------------------------------------------- 1 | # 2 | # import tkinter 3 | from tkinter import * 4 | 5 | win = Tk() 6 | win.title("CHitkara University") 7 | # win.geometry("800x400+100+50") 8 | 9 | # win.config(bg="yellow") 10 | win["bg"] = "red" 11 | # win.resizable(False, False) 12 | 13 | # win.attributes('-alpha', .5) # for changing the opacity 14 | 15 | #How to show above window on center. 16 | width = 800 17 | height = 500 18 | 19 | screenWidth = win.winfo_screenwidth() 20 | screenHeight = win.winfo_screenheight() 21 | 22 | x = int((screenWidth/2-width/2)) 23 | y = int((screenHeight/2-height/2)) 24 | win.geometry(f"{width}x{height}+{x}+{y}") 25 | 26 | 27 | 28 | win.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/buttonExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | def btnFun(): 4 | lb.config(text="Somebody has clicked on button") 5 | 6 | root = Tk() 7 | 8 | 9 | width = 800 10 | height = 500 11 | 12 | screenWidth = root.winfo_screenwidth() 13 | screenHeight = root.winfo_screenheight() 14 | x = int((screenWidth/2-width/2)) 15 | y = int((screenHeight/2-height/2)) 16 | root.geometry(f"{width}x{height}+{x}+{y}") 17 | 18 | btn = Button(root, text = "Click Me", font=(25), command=btnFun, relief="solid") 19 | btn.place(x=100, y=100, width=100, height=30) 20 | 21 | lb = Label(root, text="", font=(30)) 22 | lb.place(x=100, y=160) 23 | 24 | 25 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "students": [ 3 | { 4 | "id": "145821986841754", 5 | "name": "Rakesh", 6 | "email": "rakesh@gmail.com", 7 | "city": "Noida" 8 | }, 9 | { 10 | "id": "323263539833556", 11 | "name": "Rakesh", 12 | "email": "rakesh@gmail.com", 13 | "city": "Noida" 14 | }, 15 | { 16 | "id": "297036597882338", 17 | "name": "Rakesh", 18 | "email": "rakesh@gmail.com", 19 | "city": "Noida" 20 | }, 21 | { 22 | "id": "231820440199638", 23 | "name": "Rakesh", 24 | "email": "rakesh@gmail.com", 25 | "city": "Noida" 26 | }, 27 | { 28 | "id": "125955267677134", 29 | "name": "Rakesh", 30 | "email": "rakesh@gmail.com", 31 | "city": "Noida" 32 | }, 33 | { 34 | "id": "324056401167073", 35 | "name": "rakesh", 36 | "email": "rakesh@gmail.com", 37 | "city": "Noida" 38 | }, 39 | { 40 | "id": "565430546816326", 41 | "name": "Rakesh", 42 | "email": "rakesh1@gmail.com", 43 | "city": "Noida" 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/entryExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | def showFun(): 4 | lb.config(text=boxText.get()) 5 | 6 | root = Tk() 7 | 8 | 9 | width = 800 10 | height = 500 11 | 12 | screenWidth = root.winfo_screenwidth() 13 | screenHeight = root.winfo_screenheight() 14 | x = int((screenWidth/2-width/2)) 15 | y = int((screenHeight/2-height/2)) 16 | root.geometry(f"{width}x{height}+{x}+{y}") 17 | 18 | boxText = StringVar() 19 | 20 | box = Entry(root, font=(30), textvariable=boxText) 21 | box.place(x=20, y=20, width=300, height=30) 22 | 23 | btn = Button(root, text = "Show Text", command=showFun) 24 | btn.place(x=20, y=60) 25 | 26 | lb = Label(root, text = "", font=(25)) 27 | lb.place(x=20, y=100) 28 | 29 | 30 | 31 | 32 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/frameExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter.messagebox import showerror, showinfo, showwarning 3 | import uuid 4 | import json 5 | import os 6 | 7 | def getStudents(): 8 | if not os.path.exists('data.json'): 9 | with open('data.json', 'w') as file: 10 | file.write(json.dumps({"students":[]})) 11 | else: 12 | with open('data.json', 'r') as file: 13 | return json.loads(file.read()) 14 | 15 | 16 | def registerStudent(): 17 | student = {} 18 | student["id"] = str(uuid.uuid4().int)[:15:] 19 | student["name"] = name.get() 20 | student["email"] = email.get() 21 | student["city"] = city.get() 22 | 23 | if not all([student["name"], student["email"], student["city"]]): 24 | showerror(title="Fields Required", message="Kindly fill the all the fields") 25 | else: 26 | data = getStudents() 27 | studentsData = list(filter(lambda stu: stu["email"]==student["email"], data["students"])) 28 | 29 | if len(studentsData) > 0: 30 | showwarning(title="Student Already Exists", message="Can't add students") 31 | return 32 | 33 | data["students"].append(student) 34 | 35 | with open('data.json', 'w') as file: 36 | # file.write(json.dumps(data)) 37 | json.dump(data, file, indent=4) 38 | showinfo(title="Registred Successfully", message="Student has registered successfully") 39 | 40 | 41 | root = Tk() 42 | 43 | 44 | width = 800 45 | height = 500 46 | 47 | screenWidth = root.winfo_screenwidth() 48 | screenHeight = root.winfo_screenheight() 49 | x = int((screenWidth/2-width/2)) 50 | y = int((screenHeight/2-height/2)) 51 | root.geometry(f"{width}x{height}+{x}+{y}") 52 | 53 | lb = Label(root, text = "Student Registration System", bg="red", fg="white", relief="groove", font=(30)) 54 | lb.pack(side=TOP, fill=X, ipadx=20) 55 | 56 | #frame is like box/div 57 | registrationFrame = Frame(root, bg="teal") 58 | registrationFrame.place(relx=.5, rely=.5, anchor="center", width=500, height=300) 59 | 60 | name = StringVar() 61 | email = StringVar() 62 | city = StringVar() 63 | 64 | nameLabel = Label(registrationFrame, text = "Enter Name:", bg="teal", font=(25), fg="white") 65 | nameLabel.place(x=30, y=30) 66 | nameEntry = Entry(registrationFrame, textvariable=name, font=(20)) 67 | nameEntry.place(x=150, y=30, width=300, height=30) 68 | 69 | emailLabel = Label(registrationFrame, text = "Enter Email:", bg="teal", font=(25), fg="white") 70 | emailLabel.place(x=30, y=80) 71 | emailEntry = Entry(registrationFrame, textvariable=email, font=(20)) 72 | emailEntry.place(x=150, y=80, width=300, height=30) 73 | 74 | 75 | cityLabel = Label(registrationFrame, text = "Enter City:", bg="teal", font=(25), fg="white") 76 | cityLabel.place(x=30, y=130) 77 | cityEntry = Entry(registrationFrame, textvariable=city, font=(20)) 78 | cityEntry.place(x=150, y=130, width=300, height=30) 79 | 80 | 81 | btn = Button(registrationFrame, text = "Register Student", command=registerStudent, font=(25), bg="yellow") 82 | btn.place(x=30, y=190, width=200, height=30) 83 | 84 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/layoutManagementFunctionExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | 5 | #to make root window center: 6 | width = 800 7 | height = 500 8 | 9 | screenWidth = root.winfo_screenwidth() 10 | screenHeight = root.winfo_screenheight() 11 | x = int((screenWidth/2-width/2)) 12 | y = int((screenHeight/2-height/2)) 13 | root.geometry(f"{width}x{height}+{x}+{y}") 14 | 15 | 16 | #Label: to show the text 17 | lb1 = Label(root, text ="Python", font=(25), bg="red", fg="white") 18 | 19 | #there are three types of layout function to show any widget inside window: 20 | #pack() - 21 | #grid() 22 | #place() 23 | 24 | # lb.pack() #bydefault pack side is Top 25 | # lb1.pack(side=LEFT, fill=Y) 26 | 27 | # lb2 = Label(root, text ="Java", font=(25), bg="red", fg="white") 28 | 29 | # lb2.pack(side=TOP, padx=20, pady=20, ipadx=20, ipady=10) 30 | 31 | 32 | #grid() - to show the widget in rows and columns 33 | # name = Label(root, text ="Name", font=(25), bg="red", fg="white") 34 | # name.grid(row=0, column=0, pady=10, padx=10) 35 | 36 | # city = Label(root, text ="City", font=(25), bg="red", fg="white") 37 | # city.grid(row=0, column=1, pady=10, padx=10) 38 | 39 | # nameValue = Label(root, text ="Pankaj", font=(25), bg="red", fg="white") 40 | # nameValue.grid(row=1, column=0) 41 | 42 | # cityValue = Label(root, text ="Delhi", font=(25), bg="red", fg="white") 43 | # cityValue.grid(row=1, column=1) 44 | 45 | 46 | #place() - to align the widgets at specific cordinates 47 | 48 | # lb1 = Label(root, text ="Chitkara", font=(25), bg="red", fg="white") 49 | # lb1.place(x=10, y=10, width=200,height=200) 50 | 51 | # lb1 = Label(root, text ="Chitkara", font=(25), bg="red", fg="white") 52 | # lb1.place(relx=.5, rely=.5, anchor="center") #anchor - n, e s w, ne, se, sw, sn, center 53 | 54 | 55 | 56 | 57 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/radioButtonExample.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | def showGender(): 4 | print(gender.get()) 5 | 6 | root = Tk() 7 | 8 | 9 | width = 800 10 | height = 500 11 | 12 | screenWidth = root.winfo_screenwidth() 13 | screenHeight = root.winfo_screenheight() 14 | x = int((screenWidth/2-width/2)) 15 | y = int((screenHeight/2-height/2)) 16 | root.geometry(f"{width}x{height}+{x}+{y}") 17 | 18 | gender = StringVar() 19 | 20 | maleRadio = Radiobutton(root, text="Male", variable=gender, value="Male", command=showGender) 21 | maleRadio.pack() 22 | 23 | femaleRadio = Radiobutton(root, text="Female", variable=gender, value="Female", command=showGender) 24 | femaleRadio.pack() 25 | 26 | 27 | 28 | root.mainloop() -------------------------------------------------------------------------------- /Unit 4/Sprint 3/Day 2/tkinterVariables.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | 5 | 6 | width = 800 7 | height = 500 8 | 9 | screenWidth = root.winfo_screenwidth() 10 | screenHeight = root.winfo_screenheight() 11 | x = int((screenWidth/2-width/2)) 12 | y = int((screenHeight/2-height/2)) 13 | root.geometry(f"{width}x{height}+{x}+{y}") 14 | 15 | 16 | #tkinter variables: StringVar(), IntVar(), DoubleVar(), BooleanVar() 17 | 18 | # name = StringVar(value = "Rakesh") 19 | # print(name.get()) 20 | # name.set("Pawan") 21 | # print(name.get()) 22 | 23 | 24 | # age = IntVar(value = 45.56) 25 | # print(age.get()) 26 | # age.set(46) 27 | # print(age.get()) 28 | 29 | 30 | # salary = DoubleVar(value = 45000.56) 31 | # print(salary.get()) 32 | # salary.set(46000.10) 33 | # print(salary.get()) 34 | 35 | # isMarried = BooleanVar(value = True) 36 | # print(isMarried.get()) 37 | # isMarried.set(False) 38 | # print(isMarried.get()) 39 | 40 | root.mainloop() --------------------------------------------------------------------------------