├── day_10_function_continue └── function_continue.py ├── day_11_class ├── class.py ├── note.md └── old.py ├── day_12_class_continue ├── class_continue.md └── class_continue.py ├── day_13_class_cont ├── class_continue.md └── class_continue.py ├── day_14 ├── __pycache__ │ ├── book.cpython-312.pyc │ └── library.cpython-312.pyc ├── book.py ├── company │ ├── __pycache__ │ │ ├── designer.cpython-312.pyc │ │ ├── developer.cpython-312.pyc │ │ └── employee.cpython-312.pyc │ ├── company.py │ ├── designer.py │ ├── developer.py │ └── employee.py ├── library.py ├── main.py ├── modules.md ├── polymorphism.md └── polymorphism │ └── polymorphism.py ├── day_15_abstraction ├── abstraction.md ├── abstraction.py └── vehicle_system │ ├── bike.py │ ├── car.py │ ├── system.py │ └── vehicle.py ├── day_16 ├── packages.md └── packages.py ├── day_17_tkinter ├── gui_application.md ├── tk_class.py └── tkinter_beg.py ├── day_17_tkinter_cont └── tkinter_count.py ├── day_18 └── tkinter_grid.py ├── day_19_calculator └── main.py ├── day_1_installation ├── day_1_installation.md └── hello_world.py ├── day_2_print_and_variable └── day_2.md ├── day_3_data_types ├── data_type.md └── data_type.py ├── day_5_data_types └── data_type.md ├── day_6_control_flow ├── control.py ├── control_flow.md ├── if-else.png └── if.png ├── day_7_control_flow ├── control_flow.md ├── for-loop.png └── while-loop.png ├── day_8_break_and_continue ├── break_and_continue.md └── break_and_continue.py ├── day_9_functions ├── functions.md └── functions.py ├── guiCalculator ├── __pycache__ │ ├── graphics.cpython-312.pyc │ └── timing.cpython-312.pyc └── project.py ├── ipo_data.json ├── library_management_system ├── __pycache__ │ └── add_book_window.cpython-312.pyc ├── add_book_window.py ├── book.py ├── library.py ├── main.py └── student.py ├── mahendra └── calc.py ├── project-1 ├── Readme.md ├── final │ └── index.py └── starter │ └── app.py ├── project-2 ├── final │ └── index.py ├── readme.md └── starter │ └── index.py ├── project-3 ├── Screenshot1.png ├── Screenshot2.png ├── final │ └── index.py ├── readme.md └── starter │ └── index.py ├── project-4 ├── Screenshot1.png ├── Screenshot2.png ├── final │ └── app.py ├── readme.md └── starter │ └── app.py ├── project-5-calc ├── app.py ├── img.png └── readme.md ├── project-6-dictionary ├── Readme.md ├── app.py └── p1.png ├── project-7-selenium-todo-automation ├── Readme.md ├── todo.png └── todo.py ├── readme.md └── selenium ├── abc.json ├── automate.py └── scrap.py /day_10_function_continue/function_continue.py: -------------------------------------------------------------------------------- 1 | # def add(a,b): 2 | # print("") 3 | # return a + b 4 | 5 | # total = add(2,4) 6 | # print(total) 7 | 8 | total = lambda a, b, c: a +b + c 9 | print(total(3,4, 3)) -------------------------------------------------------------------------------- /day_11_class/class.py: -------------------------------------------------------------------------------- 1 | class Car: 2 | def __init__(self, name, color, fuel_type): 3 | self.name = name 4 | self.color = color 5 | self.fuel_type = fuel_type 6 | 7 | def start(self): 8 | print(f"Starting car {self.name} {self.color} {self.fuel_type}") 9 | 10 | 11 | car_1 = Car("BMW", "red", "petrol") 12 | car_2 = Car("Audi", "blue", "diesel") 13 | 14 | car_1.start() 15 | car_2.start() -------------------------------------------------------------------------------- /day_11_class/note.md: -------------------------------------------------------------------------------- 1 | - Earlier programming languages are recognized as procedural languages. 2 | - Procedural languages are a set of instructions that tell the computer what to do step by step. 3 | - Functional programming is a programming paradigm where programs are constructed by applying and composing functions. 4 | 5 | ## Problems with procedural programming 6 | - Procedural programming is not very flexible. 7 | - It is not easy to maintain. 8 | - It is not easy to extend. 9 | - It is not easy to reuse. 10 | - It is not easy to test. 11 | 12 | ## Object Oriented Programming 13 | - Object Oriented Programming is a programming paradigm where programs are constructed by objects. 14 | - An object is a collection of data and methods that operate on its data. 15 | - Objects are instances of classes. 16 | - A class is a blueprint for creating objects. 17 | - A class defines the properties and methods of an object. 18 | - A class can be defined as a user-defined data type. 19 | - A class can have data members and member functions. 20 | 21 | ## Classes 22 | - A class is a user-defined data type. 23 | - A class is the blueprint for creating objects. 24 | - A class defines the properties and methods of an object. 25 | - A class can have data members and member functions. 26 | 27 | ## Objects 28 | - Real world entities are represented as objects. 29 | 30 | ### Class Syntax 31 | ```python 32 | class ClassName: 33 | # class body 34 | 35 | ``` 36 | 37 | ### Class naming convention 38 | - Class names should start with a capital letter. 39 | - Class names should not contain spaces. 40 | - Class names should not start with a number. 41 | - Class names should not contain special characters. 42 | 43 | Example: 44 | ```python 45 | class Person: 46 | name = "John" # member variable 47 | age = 36 # member variable 48 | country = "Norway" # member variable 49 | 50 | # member function or method 51 | def details(self): 52 | print("Name: ", self.name) 53 | print("Age: ", self.age) 54 | print("Country: ", self.country) 55 | 56 | p1 = Person() 57 | p1.details() 58 | 59 | p1.name = "John Doe" 60 | p1.age = 40 61 | 62 | p1.details() 63 | ``` 64 | 65 | This is not very useful if we want to create multiple objects of the same class. We can use the `__init__()` method to initialize the object. 66 | 67 | ### The `__init__()` method 68 | 69 | - The `__init__()` method is a special method that is called when an object is created. 70 | - The `__init__()` method is also known as the constructor method. 71 | - The `__init__()` method is used to initialize the object. 72 | - The `__init__()` method is called automatically when an object is created. 73 | - The `__init__()` method takes the `self` parameter which is a reference to the current instance of the class. 74 | - The `__init__()` method can be used to initialize the object with values. 75 | 76 | Example: 77 | ```python 78 | class Person: 79 | def __init__(self, name, age, country): 80 | self.name = name 81 | self.age = age 82 | self.country = country 83 | 84 | def details(self): 85 | print("Name: ", self.name) 86 | print("Age: ", self.age) 87 | print("Country: ", self.country) 88 | 89 | p1 = Person("John", 36, "Norway") 90 | 91 | p1.details() 92 | ``` 93 | 94 | ### The `self` parameter 95 | - The `self` parameter is a reference to the current instance of the class. 96 | - The `self` parameter is used to access the class variables and methods. 97 | 98 | 99 | 100 | Real world example of using class insted of procedural programming: 101 | 102 | Suppose we want a car with the properties like model, color, fuel type, etc. Also include a method start() to start the car. 103 | 104 | ### Procedural Programming 105 | ```python 106 | model = "BMW" 107 | color = "Black" 108 | fuel_type = "Petrol" 109 | 110 | def start(): 111 | print(f"Starting the car {model} {color} {fuel_type}") 112 | 113 | start() 114 | ``` 115 | 116 | This is not very useful if we want to create multiple cars. Because we have to create multiple variables for each car. Below is the example of creating multiple cars. 117 | 118 | ```python 119 | model1 = "BMW" 120 | color1 = "Black" 121 | fuel_type1 = "Petrol" 122 | 123 | model2 = "Audi" 124 | color2 = "White" 125 | fuel_type2 = "Diesel" 126 | 127 | def start(model, color, fuel_type): 128 | print(f"Starting the car {model} {color} {fuel_type}") 129 | 130 | start(model1, color1, fuel_type1) 131 | start(model2, color2, fuel_type2) 132 | ``` 133 | 134 | This is not very useful if we want to create multiple cars. We can use the class to create multiple cars. 135 | 136 | ### Object Oriented Programming 137 | ```python 138 | class Car: 139 | def __init__(self, model, color, fuel_type): 140 | self.model = model 141 | self.color = color 142 | self.fuel_type = fuel_type 143 | 144 | def start(self): 145 | print(f"Starting the car {self.model} {self.color} {self.fuel_type}") 146 | 147 | car1 = Car("BMW", "Black", "Petrol") 148 | car2 = Car("Audi", "White", "Diesel") 149 | 150 | car1.start() 151 | car2.start() 152 | ``` 153 | 154 | ### Advantages: 155 | - No need to create multiple variables for each car. 156 | 157 | 158 | ## Another example of class 159 | Create a class called calculator with the following methods: 160 | - add(x, y) 161 | - subtract(x, y) 162 | - multiply(x, y) 163 | - divide(x, y) 164 | 165 | ```python 166 | class Calculator: 167 | def __init__(self, x, y): 168 | self.x = x 169 | self.y = y 170 | 171 | def add(self): 172 | return self.x + self.y 173 | 174 | def subtract(self): 175 | return self.x - self.y 176 | 177 | def multiply(self): 178 | return self.x * self.y 179 | 180 | def divide(self): 181 | return self.x/self.y 182 | 183 | 184 | cal = Calculator(10, 5) 185 | print(cal.add()) 186 | print(cal.subtract()) 187 | print(cal.multiply()) 188 | print(cal.divide()) 189 | 190 | 191 | ``` 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /day_11_class/old.py: -------------------------------------------------------------------------------- 1 | car_name_1 = "BMW" 2 | car_color_1 = "red" 3 | car_fuel_type_1 = "petrol" 4 | 5 | car_name_2 = "Audi" 6 | car_color_2 = "blue" 7 | car_fuel_type_2 = "diesel" 8 | 9 | 10 | def start(name, color, fuel_type): 11 | print(f"Starting car {name} {color} {fuel_type}") 12 | 13 | 14 | start(car_name_1, car_color_1, car_fuel_type_1) 15 | start(car_name_2, car_color_2, car_fuel_type_2) -------------------------------------------------------------------------------- /day_12_class_continue/class_continue.md: -------------------------------------------------------------------------------- 1 | # Access Modifiers 2 | - determines the visibility and accessibility of a class's properties and methods 3 | - In Python, there are three types of access modifiers: 4 | - public 5 | - protected 6 | - private 7 | 8 | - In python, access modifiers are not strictly enforced 9 | 10 | ## Why do we need access modifiers? 11 | - To protect the data from accidental manipulation 12 | - To achieve data encapsulation 13 | 14 | ## Public Access Modifier 15 | - By default, all the properties and methods are public 16 | - We can access public properties and methods from anywhere in the program 17 | 18 | Example: 19 | ```python 20 | class Car: 21 | def __init__(self, model, color, fuel_type): 22 | self.model = model 23 | self.color = color 24 | self.fuel_type = fuel_type 25 | 26 | def start(self): 27 | print(f"Starting the car {self.model} {self.color} {self.fuel_type}") 28 | 29 | car1 = Car("BMW", "Black", "Petrol") 30 | car2 = Car("Audi", "White", "Diesel") 31 | 32 | car1.start() 33 | car2.start() 34 | ``` 35 | 36 | ## Protected Access Modifier 37 | - We can declare a property or method as protected by adding a single underscore before the name of the property or method 38 | - Can be accessed only within the class and its subclasses 39 | - To declare a member as protected, we need to add a single underscore before the name of the member (_) 40 | 41 | Example: 42 | ```python 43 | class Car: 44 | def __init__(self, model, color, fuel_type): 45 | self.model = model 46 | self.color = color 47 | self._fuel_type = fuel_type 48 | 49 | def start(self): 50 | print(f"Starting the car {self.model}{self.color} {self._fuel_type}") 51 | 52 | car1 = Car("BMW", "Black", "Petrol") 53 | 54 | print(car1._fuel_type) 55 | ``` 56 | 57 | ### When to use protected access modifier? 58 | 59 | - When we want to prevent the data from being modified accidentally 60 | - When we want to prevent the data from being accessed from outside the class 61 | 62 | 63 | 64 | ## Private Access Modifier 65 | - We can declare a property or method as private by adding a double underscore before the name of the property or method (__) 66 | - Can be accessed only within the class 67 | 68 | Example: 69 | ```python 70 | class BankAccount: 71 | def __init__(self, initial_balance): 72 | self.__balance = initial_balance # Private attribute 73 | 74 | def deposit(self, amount): 75 | self.__balance += amount 76 | 77 | def withdraw(self, amount): 78 | if amount <= self.__balance: 79 | self.__balance -= amount 80 | else: 81 | print("Insufficient funds") 82 | 83 | # Usage 84 | account = BankAccount(1000) 85 | account.deposit(500) 86 | account.withdraw(200) 87 | 88 | ``` 89 | 90 | # Getters and Setters 91 | Getters and setters are used to access or modify the private attributes of a class. 92 | 93 | ## Getters 94 | - Getters are used to access the private attributes of a class 95 | - Getters are also called accessor methods 96 | 97 | Real world example: 98 | ```python 99 | class BankAccount: 100 | def __init__(self, initial_balance): 101 | self.__balance = initial_balance # Private attribute 102 | 103 | def deposit(self, amount): 104 | self.__balance += amount 105 | 106 | def withdraw(self, amount): 107 | if amount <= self.__balance: 108 | self.__balance -= amount 109 | else: 110 | print("Insufficient funds") 111 | 112 | def get_balance(self): 113 | return self.__balance 114 | 115 | # Usage 116 | account = BankAccount(5000) 117 | account.deposit(1000) 118 | account.withdraw(2000) 119 | 120 | print(account.get_balance()) 121 | ``` 122 | 123 | ## Setters 124 | - Setters are used to modify the private attributes of a class 125 | - Setters are also called mutator methods 126 | 127 | Real world example: 128 | ```python 129 | class BankAccount: 130 | def __init__(self, initial_balance): 131 | self.__balance = initial_balance # 132 | 133 | def deposit(self, amount): 134 | self.__balance += amount 135 | 136 | def withdraw(self, amount): 137 | if amount <= self.__balance: 138 | self.__balance -= amount 139 | else: 140 | print("Insufficient funds") 141 | 142 | def get_balance(self): 143 | return self.__balance 144 | 145 | -------------------------------------------------------------------------------- /day_12_class_continue/class_continue.py: -------------------------------------------------------------------------------- 1 | class Account: 2 | def __init__(self, account_no, holder_name, balance): 3 | self.account_no = account_no 4 | self.holder_name = holder_name 5 | self.__balance = balance 6 | 7 | 8 | def deposit(self, amount): 9 | self.__balance += amount 10 | print(f"Amount {amount} deposited successfully.\nYour new balance is {self.__balance}") 11 | 12 | def withdraw(self, amount): 13 | if self.__balance < amount: 14 | print("Insufficient balance") 15 | else: 16 | self.__balance -= amount 17 | print(f"Amount {amount} withdrawn successfully. Your new balance is {self.__balance}") 18 | 19 | 20 | def get_balance(self): 21 | return self.__balance 22 | 23 | 24 | account1 = Account( 25 | 34242332432432, 26 | "Robert", 27 | balance= 2000 28 | ) 29 | 30 | 31 | account2 = Account( 32 | 32423543543534, 33 | "Ram", 34 | balance= 5000 35 | ) 36 | 37 | 38 | print(account1.show_balance()) 39 | -------------------------------------------------------------------------------- /day_13_class_cont/class_continue.md: -------------------------------------------------------------------------------- 1 | # Magic/Dunder Methods 2 | - Dunder or magic methods in Python are the methods having two prefix and suffix underscores in the method name. 3 | - Dunder here means “Double Under (Underscores)”. These are commonly used for operator overloading. 4 | - Few examples for magic methods are: __init__, __add__, __len__, etc. 5 | 6 | ## Example of Magic Methods 7 | ```python 8 | class Employee: 9 | def __init__(self, name, id, salary): 10 | self.name = name 11 | self.id = id 12 | self.salary = salary 13 | 14 | def __str__(self): 15 | return f" Name: {self.name}\n Id: {self.id}\n Salary: {self.salary}" 16 | 17 | def __add__(self, other): 18 | return self.salary + other.salary 19 | 20 | def __len__(self): 21 | return len(self.name) 22 | 23 | def __eq__(self, other): 24 | return self.salary == other.salary 25 | 26 | def __lt__(self, other): 27 | return self.salary < other.salary 28 | 29 | def __gt__(self, other): 30 | return self.salary > other.salary 31 | 32 | def __le__(self, other): 33 | return self.salary <= other.salary 34 | 35 | def __ge__(self, other): 36 | return self.salary >= other.salary 37 | 38 | 39 | emp1 = Employee("Emp1", 1, 10000) 40 | emp2 = Employee("Emp2", 2, 20000) 41 | 42 | print(emp1) 43 | print(emp2) 44 | 45 | print(emp1 + emp2) 46 | 47 | print(len(emp1)) 48 | print(len(emp2)) 49 | 50 | print(emp1 == emp2) # emp1.__eq__(emp2) 51 | print(emp1 < emp2) # emp1.__lt__(emp2) 52 | print(emp1 > emp2) # emp1.__gt__(emp2) 53 | print(emp1 <= emp2) # emp1.__le__(emp2) 54 | print(emp1 >= emp2) # emp1.__ge__(emp2) 55 | ``` 56 | 57 | 58 | # Inheritance 59 | - It is a way to form new classes using classes that have already been defined. 60 | - The newly formed classes are called derived classes, the classes that we derive from are called base classes. 61 | 62 | ## Why do we need inheritance? 63 | - It provides reusability of a code. 64 | - We don’t have to write the same code again and again. 65 | - Also, it allows us to add more features to a class without modifying it. 66 | 67 | #### Real World scenario where inheritance can be applied 68 | - Consider we are make employee management system for a IT company. In the company, there are many types of employees like developers, testers, managers etc. All these employees have some common behavior like all of them have name, id, salary and they also do get paid, sleep, eat etc. So, we can make a base class Employee which will have all these common behaviors. Then we can make different classes for different type of employees like Developer, Tester, Manager etc. These classes will inherit the common behavior from the base class Employee. So, we can say that the Developer, Tester, Manager etc. classes are derived from the base class Employee. Each of these classes will have its own unique behavior. For example, Developer will have a behavior of writing code, Tester will have a behavior of testing the code etc. So, we can say that the Developer, Tester, Manager etc. classes are derived from the base class Employee. 69 | 70 | ## How to implement inheritance in Python? 71 | - In Python, inheritance can be implemented by using the following syntax: 72 | ```python 73 | class BaseClass: 74 | # Body of base class 75 | 76 | class DerivedClass(BaseClass): 77 | # Body of derived class 78 | ``` 79 | 80 | - Here, the derived class inherits the base class. 81 | 82 | ## Example of Inheritance in Python 83 | ```python 84 | class Employee: 85 | def __init__(self, name, id, salary): 86 | self.name = name 87 | self.id = id 88 | self.salary = salary 89 | 90 | def display(self): 91 | print(f" Name: {self.name}\n Id: {self.id}\n Salary: {self.salary}") 92 | 93 | class Developer(Employee): 94 | # developer may have some unique attributes like, programming language, 95 | def __init__(self, name, id, salary, language): 96 | super().__init__(name, id, salary) 97 | self.language = language 98 | 99 | def display(self): # overriding 100 | # super().display() 101 | print(f" Language: {self.language}") 102 | 103 | class Designer(Employee): 104 | # designer may have some unique attributes like, designing tool, 105 | def __init__(self, name, id, salary, tool): 106 | super().__init__(name, id, salary) 107 | self.tool = tool 108 | 109 | def display(self): 110 | super().display() 111 | print(f" Tool: {self.tool}") 112 | 113 | 114 | dev1 = Developer("Dev1", 1, 10000, "Python") 115 | dev2 = Developer("Dev2", 2, 20000, "Java") 116 | 117 | des1 = Designer("Des1", 3, 30000, "Adobe XD") 118 | des2 = Designer("Des2", 4, 40000, "Figma") 119 | 120 | dev1.display() 121 | dev2.display() 122 | 123 | des1.display() 124 | des2.display() 125 | ``` 126 | -------------------------------------------------------------------------------- /day_13_class_cont/class_continue.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self, name, age, add, sal): 3 | self.name = name 4 | self.age = age 5 | self.add = add 6 | 7 | class Employee: 8 | def __init__(self,emp_id, sal): 9 | self.emp_id = emp_id 10 | self.sal = sal 11 | 12 | def display(self): 13 | print(f"Name={self.name}\n Age = {self.age}\n Address= {self.add}\n Salary= {self.sal}") 14 | 15 | class Developer(Employee, Person): 16 | def __init__(self, name, age, add, sal, programming_lang): 17 | Person.__init__(name, age, add) 18 | Employee.__init__(1, sal) 19 | self.programming_lang = programming_lang 20 | 21 | def display(self): 22 | super().display() 23 | print(f"Language= {self.programming_lang}") 24 | 25 | dev1 = Developer( 26 | "Anuj", 27 | 23, 28 | "Kathmandu", 29 | 25000, 30 | "Python" 31 | ) 32 | 33 | dev1.display() -------------------------------------------------------------------------------- /day_14/__pycache__/book.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_14/__pycache__/book.cpython-312.pyc -------------------------------------------------------------------------------- /day_14/__pycache__/library.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_14/__pycache__/library.cpython-312.pyc -------------------------------------------------------------------------------- /day_14/book.py: -------------------------------------------------------------------------------- 1 | class Book: 2 | def __init__(self, title, author): 3 | self.__title = title 4 | self.__author = author 5 | -------------------------------------------------------------------------------- /day_14/company/__pycache__/designer.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_14/company/__pycache__/designer.cpython-312.pyc -------------------------------------------------------------------------------- /day_14/company/__pycache__/developer.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_14/company/__pycache__/developer.cpython-312.pyc -------------------------------------------------------------------------------- /day_14/company/__pycache__/employee.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_14/company/__pycache__/employee.cpython-312.pyc -------------------------------------------------------------------------------- /day_14/company/company.py: -------------------------------------------------------------------------------- 1 | from developer import Developer 2 | from designer import Designer 3 | 4 | 5 | dev1 = Developer("Dev1", 1, 10000, "Python") 6 | dev2 = Developer("Dev2", 2, 20000, "Java") 7 | 8 | des1 = Designer("Des1", 3, 30000, "Adobe XD") 9 | des2 = Designer("Des2", 4, 40000, "Figma") 10 | 11 | dev1.display() 12 | dev2.display() 13 | 14 | des1.display() 15 | des2.display() -------------------------------------------------------------------------------- /day_14/company/designer.py: -------------------------------------------------------------------------------- 1 | from employee import Employee 2 | 3 | class Designer(Employee): 4 | # designer may have some unique attributes like, designing tool, 5 | def __init__(self, name, id, salary, tool): 6 | super().__init__(name, id, salary) 7 | self.tool = tool 8 | 9 | def display(self): 10 | super().display() 11 | print(f" Tool: {self.tool}") 12 | -------------------------------------------------------------------------------- /day_14/company/developer.py: -------------------------------------------------------------------------------- 1 | from employee import Employee 2 | 3 | class Developer(Employee): 4 | # developer may have some unique attributes like, programming language, 5 | def __init__(self, name, id, salary, language): 6 | super().__init__(name, id, salary) 7 | self.language = language 8 | 9 | def display(self): # overriding 10 | # super().display() 11 | print(f" Language: {self.language}") -------------------------------------------------------------------------------- /day_14/company/employee.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self, name, id, salary): 3 | self.name = name 4 | self.id = id 5 | self.salary = salary 6 | 7 | def display(self): 8 | print(f" Name: {self.name}\n Id: {self.id}\n Salary: {self.salary}") 9 | -------------------------------------------------------------------------------- /day_14/library.py: -------------------------------------------------------------------------------- 1 | from book import Book 2 | 3 | class Library: 4 | def __init__(self): 5 | self.books = [] 6 | 7 | def add_book(self, book): 8 | self.books.append(book) 9 | 10 | def count_books(self): 11 | print(f"Total books:{len(self.books)}") 12 | -------------------------------------------------------------------------------- /day_14/main.py: -------------------------------------------------------------------------------- 1 | from book import Book 2 | from library import Library 3 | 4 | book_1 = Book("Introduction to Computer", "Charles") 5 | 6 | library = Library() 7 | library.add_book(book_1) 8 | 9 | library.count_books() -------------------------------------------------------------------------------- /day_14/modules.md: -------------------------------------------------------------------------------- 1 | 2 | # Modules in Python 3 | 4 | - Modules are files containing Python code. 5 | 6 | - Modules can be imported into other modules or into the main module. 7 | 8 | - Modules are used to organize code into logical units. 9 | 10 | - Modules are imported using the `import` keyword. 11 | 12 | ## Creating a module 13 | 14 | Let's first write normal python code. 15 | ```python 16 | 17 | class Book: 18 | self __init__(self, title, author): 19 | self.title = title 20 | self.author = author 21 | 22 | def display_info(self): 23 | print(f"{self.title} by {self.author}") 24 | 25 | 26 | class Library: 27 | def __init__(self): 28 | self.books = [] 29 | 30 | def add_book(self, book): 31 | self.books.append(book) 32 | 33 | def display_books(self): 34 | for book in self.books: 35 | book.display_info() 36 | 37 | 38 | book1 = Book("Introduction to Programming"," Ram ") 39 | book2 = Book("Introduction to Python"," Shyam ") 40 | 41 | library = Library() 42 | library.add_book(book1) 43 | library.add_book(book2) 44 | 45 | library.display_books() 46 | 47 | ``` 48 | 49 | here, when the program gets bigger, it will be difficult to manage the code. So, we can create a module for each class. 50 | 51 | Let's create a module for the `Book` class. 52 | 53 | ```python 54 | # book.py 55 | 56 | class Book: 57 | self __init__(self, title, author): 58 | self.title = title 59 | self.author = author 60 | 61 | def display_info(self): 62 | print(f"{self.title} by {self.author}") 63 | ``` 64 | 65 | Now, we can import the `Book` class from the `book` module. 66 | 67 | ```python 68 | import book 69 | ``` 70 | 71 | Now, we can use the `Book` class from the `book` module. 72 | 73 | ```python 74 | book1 = book.Book("Introduction to Programming"," Ram ") 75 | 76 | book1.display_info() 77 | ``` 78 | 79 | Instead of using book.Book, we can use alias name for the module. 80 | 81 | ```python 82 | import book as bk 83 | 84 | book1 = bk.Book("Introduction to Programming"," Ram ") 85 | 86 | book1.display_info() 87 | ``` 88 | 89 | We can also import the `Book` class directly from the `book` module. 90 | 91 | ```python 92 | from book import Book 93 | 94 | book1 = Book("Introduction to Programming"," Ram ") 95 | 96 | book1.display_info() 97 | ``` 98 | 99 | We can also import all the classes from the `book` module. 100 | 101 | ```python 102 | from book import * 103 | 104 | book1 = Book("Introduction to Programming"," Ram ") 105 | 106 | book1.display_info() 107 | ``` 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /day_14/polymorphism.md: -------------------------------------------------------------------------------- 1 | # Polymorphism 2 | - Poly means many and morphism means forms. So polymorphism means many forms. 3 | 4 | In programming, polymorphism refers to methods/functions/operators having the same name but different implementations. 5 | 6 | Example of polymorphic functions: 7 | `len()` function is a polymorphic function because it can be used to find the length of a string, list, tuple, dictionary etc. 8 | 9 | ```python 10 | print(len("Hello")) 11 | 12 | print(len([1, 2, 3, 4, 5])) 13 | 14 | print(len((1, 2, 3, 4, 5))) 15 | 16 | print(len({"name": "John", "age": 36})) 17 | ``` 18 | 19 | Example of polymorphic operators: 20 | `+` operator is a polymorphic operator because it can be used to add two integers or two floats or two strings. 21 | 22 | ```python 23 | print(10 + 20) 24 | 25 | print(10.5 + 20.5) 26 | 27 | print("Hello" + "World") 28 | ``` 29 | 30 | Polymorphism in OOP: 31 | - Polymorphism is often used in class method, where a method having the same name is defined in multiple classes. 32 | 33 | Example: 34 | ```python 35 | class Dog: 36 | def sound(self): 37 | print("Bark") 38 | 39 | class Cat: 40 | def sound(self): 41 | print("Meow") 42 | 43 | def make_sound(animal): 44 | 45 | animal.sound() 46 | 47 | dog = Dog() 48 | cat = Cat() 49 | 50 | dog.sound() 51 | cat.sound() 52 | ``` 53 | 54 | Another real world example: 55 | ```python 56 | 57 | class Shape: 58 | def area(self): 59 | pass 60 | 61 | class Square(Shape): 62 | def __init__(self, length): 63 | self.length = length 64 | 65 | def area(self): 66 | return self.length * self.length 67 | 68 | class Rectangle(Shape): 69 | def __init__(self, length, width): 70 | self.length = length 71 | self.width = width 72 | 73 | def area(self): 74 | return self.length * self.width 75 | 76 | 77 | square = Square(5) 78 | rectangle = Rectangle(5, 10) 79 | 80 | print(square.area()) 81 | print(rectangle.area()) 82 | ``` 83 | 84 | Real World Example Assignment: 85 | ```python 86 | # Base class 87 | class Employee: 88 | def __init__(self, name, role): 89 | self.name = name 90 | self.role = role 91 | 92 | def calculate_salary(self): 93 | return "Base salary calculation" 94 | 95 | # Subclass 1: Manager 96 | class Manager(Employee): 97 | def __init__(self, name, team_size): 98 | super().__init__(name, role="Manager") 99 | self.team_size = team_size 100 | 101 | def calculate_salary(self): 102 | base_salary = 50000 103 | team_bonus = self.team_size * 1000 104 | return base_salary + team_bonus 105 | 106 | # Subclass 2: Developer 107 | class Developer(Employee): 108 | def __init__(self, name, programming_language): 109 | super().__init__(name, role="Developer") 110 | self.programming_language = programming_language 111 | 112 | def calculate_salary(self): 113 | base_salary = 60000 114 | language_bonus = 2000 if self.programming_language == "Python" else 0 115 | return base_salary + language_bonus 116 | 117 | # Function that calculates salary for any employee 118 | def calculate_employee_salary(employee): 119 | return employee.calculate_salary() 120 | 121 | # Create instances of Manager and Developer 122 | manager = Manager(name="Alice", team_size=5) 123 | developer = Developer(name="Bob", programming_language="Python") 124 | 125 | # Use the calculate_employee_salary function with different employees 126 | print(calculate_employee_salary(manager)) # Output: Manager's salary calculation with team bonus 127 | print(calculate_employee_salary(developer)) # Output: Developer's salary calculation with language bonus 128 | 129 | ``` -------------------------------------------------------------------------------- /day_14/polymorphism/polymorphism.py: -------------------------------------------------------------------------------- 1 | # class Shape: 2 | # def draw(self): 3 | # ... 4 | 5 | 6 | class Rectangle(): 7 | def __init__(self, height, width): 8 | self.height = height 9 | self.width = width 10 | 11 | def draw(self): 12 | print(f"Drawing Rectangle of {self.height} and {self.width}") 13 | 14 | 15 | class Square(): 16 | def __init__(self, length): 17 | self.length = length 18 | 19 | 20 | def draw(self): 21 | print(f"Drawing square of length {self.length}") -------------------------------------------------------------------------------- /day_15_abstraction/abstraction.md: -------------------------------------------------------------------------------- 1 | # Abstraction 2 | 3 | - Abstraction is the process of hiding the internal details and showing only the functionality. 4 | 5 | - Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter). 6 | 7 | - Abstract classes may not be instantiated, and its abstract methods must be implemented by its subclasses. 8 | 9 | - Abstract classes are denoted by the @abstractmethod decorator. 10 | 11 | - Abstract methods are methods that are declared, but contains no implementation. 12 | 13 | 14 | In Python, we can create abstract classes by inheriting from the ABC class of the abc module. 15 | 16 | ```python 17 | from abc import ABC, abstractmethod 18 | 19 | class Vehicle(ABC): 20 | @abstractmethod 21 | def start(self): 22 | pass 23 | 24 | @abstractmethod 25 | def stop(self): 26 | pass 27 | 28 | class Car(Vehicle): 29 | def __init__(self, name): 30 | self.name = name 31 | 32 | def start(self): 33 | print(f"{self.name} started") 34 | 35 | def stop(self): 36 | print(f"{self.name} stopped") 37 | 38 | car = Car("Honda City") 39 | car.start() 40 | car.stop() 41 | ``` 42 | 43 | 44 | simple example of a network request and caching using an abstract class in Python. We'll define an abstract class representing a data fetcher, and then create concrete subclasses for fetching data from the network and implementing a basic caching mechanism. 45 | 46 | ```python 47 | from abc import ABC, abstractmethod 48 | 49 | class DataFetcher(ABC): 50 | @abstractmethod 51 | def fetch_data(self, key): 52 | pass 53 | 54 | class NetworkDataFetcher(DataFetcher): 55 | def fetch_data(self, key): 56 | # Simulate fetching data from a network 57 | print(f"Fetching data from network for key: {key}") 58 | # In a real-world scenario, you would make an actual network request here 59 | return f"Network data for {key}" 60 | 61 | class CachingDataFetcher(DataFetcher): 62 | def __init__(self, data_fetcher): 63 | self.data_fetcher = data_fetcher 64 | self.cache = {} 65 | 66 | def fetch_data(self, key): 67 | # Check if data is present in the cache 68 | if key in self.cache: 69 | print(f"Fetching data from cache for key: {key}") 70 | return self.cache[key] 71 | else: 72 | # If not present in the cache, fetch data from the underlying data fetcher 73 | data = self.data_fetcher.fetch_data(key) 74 | # Store the data in the cache for future use 75 | self.cache[key] = data 76 | return data 77 | 78 | # Example usage: 79 | # Create a network data fetcher 80 | network_fetcher = NetworkDataFetcher() 81 | 82 | # Create a caching data fetcher using the network fetcher 83 | caching_fetcher = CachingDataFetcher(network_fetcher) 84 | 85 | # Fetch data using the caching fetcher 86 | result1 = caching_fetcher.fetch_data("key1") 87 | result2 = caching_fetcher.fetch_data("key2") 88 | result3 = caching_fetcher.fetch_data("key1") # This should be fetched from the cache 89 | 90 | print(result1) 91 | print(result2) 92 | print(result3) 93 | 94 | ``` -------------------------------------------------------------------------------- /day_15_abstraction/abstraction.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class Shape(ABC): 4 | 5 | @abstractmethod 6 | def area(self): 7 | pass 8 | 9 | class Circle(Shape): 10 | 11 | def area(self, radius): 12 | print('Area of circle is:', 3.1416 * radius**2) 13 | 14 | 15 | class Rectangle(Shape): 16 | def area(self, length, bredth): 17 | print('Area of rectangle is:', length * bredth) 18 | 19 | 20 | circle = Circle() 21 | circle.area(5) -------------------------------------------------------------------------------- /day_15_abstraction/vehicle_system/bike.py: -------------------------------------------------------------------------------- 1 | from vehicle import Vehicle 2 | 3 | class Bike(Vehicle): 4 | 5 | def start(self): 6 | print("Starting bike..") 7 | -------------------------------------------------------------------------------- /day_15_abstraction/vehicle_system/car.py: -------------------------------------------------------------------------------- 1 | from vehicle import Vehicle 2 | 3 | class Car(Vehicle): 4 | 5 | def start(self): 6 | print("Starting Car") 7 | -------------------------------------------------------------------------------- /day_15_abstraction/vehicle_system/system.py: -------------------------------------------------------------------------------- 1 | from car import Car 2 | from bike import Bike 3 | 4 | car = Car() 5 | car.start() 6 | 7 | bike = Bike() 8 | bike.start() -------------------------------------------------------------------------------- /day_15_abstraction/vehicle_system/vehicle.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class Vehicle(ABC): 4 | 5 | @abstractmethod 6 | def start(self): 7 | ... 8 | -------------------------------------------------------------------------------- /day_16/packages.md: -------------------------------------------------------------------------------- 1 | # Packages In Python 2 | 3 | - A package is a collection of modules 4 | - A module is a single Python file 5 | - A package is a directory of Python modules containing an additional __init__.py file 6 | - A package can have sub-packages 7 | 8 | ## Python Standard Library 9 | - Python comes with a standard library of modules 10 | - The standard library is a set of modules that are part of the Python distribution 11 | - The standard library is installed with Python 12 | - The standard library is always 13 | 14 | - Examples of standard library modules: 15 | - os 16 | - sys 17 | - math 18 | - random 19 | - datetime 20 | 21 | 22 | ## Third Party Packages 23 | 24 | - Third party packages are packages that are not part of the Python standard library 25 | - These are are created by other developers 26 | - These are installed using a package manager 27 | 28 | - We can use `pip` to install packages 29 | 30 | Link to [pip](https://pypi.org/project/pip/) 31 | 32 | ## PiP commands 33 | - `pip install ` - installs a package 34 | - `pip uninstall ` - uninstalls a package 35 | - `pip list` - lists all installed packages 36 | - `pip freeze` - lists all installed packages and their versions 37 | - `pip show ` - shows information about a package 38 | - `pip search ` - searches for a package 39 | 40 | 41 | 42 | ## Python Example Using package 43 | 44 | ```python 45 | import requests 46 | 47 | def get_random_advice(): 48 | url = "https://api.adviceslip.com/advice" 49 | response: requests.Request = requests.get(url) 50 | 51 | if response.status_code == 200: 52 | advice_data = response.json() 53 | 54 | print(type(advice_data)) 55 | return advice_data["slip"]["advice"] 56 | else: 57 | print("Error fetching advice") 58 | return None 59 | 60 | if __name__ == "__main__": 61 | random_advice = get_random_advice() 62 | 63 | if random_advice: 64 | print("Random Advice:") 65 | print(random_advice) 66 | 67 | ``` 68 | 69 | We can use `dataclasses` to create a class that represents the data we get back from the API -------------------------------------------------------------------------------- /day_16/packages.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | API_URL = 'https://api.adviceslip.com/advice' 4 | 5 | def get_advice(): 6 | response = requests.get(API_URL) 7 | # print(response.status_code) 8 | 9 | if response.status_code == 200: 10 | data = response.json() 11 | 12 | advice = data['slip']['advice'] 13 | return advice 14 | 15 | else: 16 | return 'Something went wrong' 17 | 18 | random_advice = get_advice() 19 | 20 | print(random_advice) -------------------------------------------------------------------------------- /day_17_tkinter/gui_application.md: -------------------------------------------------------------------------------- 1 | # Tkinter in Python 2 | 3 | - It is Python's standard GUI (Graphical User Interface) package 4 | - It allows us to create functional desktop applications with minimal lines of code 5 | - It is cross-platform, meaning it works on Windows, Mac, and Linux 6 | - Comes with Python, so no need to install it 7 | 8 | ## Tkinter Fundamentals 9 | The main components of a Tkinter application are: 10 | 11 | - **Window** - The main window of the application 12 | - **Widgets** - The elements that make up the application's GUI 13 | - **Layout** - How the widgets are arranged in the window 14 | 15 | ## Tkinter Example 16 | 17 | ```python 18 | import tkinter as tk 19 | 20 | window = tk.Tk() 21 | window.title("My First GUI Program") 22 | window.minsize(width=500, height=300) 23 | 24 | # Label 25 | my_label = tk.Label(text="I am a label", font=("Arial", 24, "bold")) 26 | my_label.pack(side="left") 27 | 28 | # Button 29 | def button_clicked(): 30 | print("I got clicked") 31 | my_label.config(text="Button got clicked") 32 | 33 | button = tk.Button(text="Click Me", command=button_clicked) 34 | 35 | button.pack() 36 | 37 | window.mainloop() 38 | ``` 39 | 40 | ### Explanation: 41 | 42 | - `import tkinter as tk` - imports the tkinter package and gives it the alias `tk` 43 | 44 | - `window = tk.Tk()` - creates a new window and assigns it to the variable `window` 45 | 46 | - `window.title("My First GUI Program")` - sets the title of the window 47 | 48 | - `window.minsize(width=500, height=300)` - sets the minimum size of the window 49 | 50 | - `my_label = tk.Label(text="I am a label", font=("Arial", 24, "bold"))` - creates a label widget and assigns it to the variable `my_label` 51 | 52 | - `my_label.pack(side="left")` - packs the label widget into the window and places it on the left side 53 | 54 | - `button = tk.Button(text="Click Me", command=button_clicked)` - creates a button widget and assigns it to the variable `button` 55 | 56 | - `button.pack()` - packs the button widget into the window 57 | 58 | - `window.mainloop()` - runs the application's main loop, which is an infinite loop that waits for events to happen 59 | 60 | 61 | ## Placing Widgets 62 | 63 | There are three different ways to place widgets in a window: 64 | 65 | - **Pack** - organizes widgets in blocks before placing them in the parent widget 66 | - **Place** - organizes widgets by placing them in a specific position in the parent widget 67 | 68 | - **Grid** - organizes widgets in a table-like structure in the parent widget 69 | 70 | -------------------------------------------------------------------------------- /day_17_tkinter/tk_class.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | def my_add(): 5 | try: 6 | num1 = int(my_input1.get()) 7 | num2 = int(my_input2.get()) 8 | result_value = num1 + num2 9 | result.configure(text=f"Result: {result_value}") 10 | except ValueError: 11 | result.configure(text="Invalid input. Please enter numbers.") 12 | 13 | 14 | def my_sub(): 15 | try: 16 | num1 = int(my_input1.get()) 17 | num2 = int(my_input2.get()) 18 | result_value = num1 - num2 19 | result.configure(text=f"Result: {result_value}") 20 | except ValueError: 21 | result.configure(text="Invalid input. Please enter numbers.") 22 | 23 | def my_mul(): 24 | try: 25 | num1 = int(my_input1.get()) 26 | num2 = int(my_input2.get()) 27 | result_value = num1 * num2 28 | result.configure(text=f"Result: {result_value}") 29 | except ValueError: 30 | result.configure(text="Invalid input. Please enter numbers.") 31 | 32 | def my_div(): 33 | try: 34 | num1 = int(my_input1.get()) 35 | num2 = int(my_input2.get()) 36 | 37 | if num2 == 0 : 38 | result.configure(text="Invalid input. Please enter valid numbers.") 39 | else: 40 | result_value = num1 / num2 41 | result.configure(text=f"Result: {result_value}") 42 | except ValueError: 43 | result.configure(text="Invalid input. Please enter numbers.") 44 | window = tk.Tk() 45 | window.title("Calculator") 46 | window.geometry("320x200") 47 | 48 | # First Number Frame1 49 | frame1 = tk.Frame(master=window) 50 | frame1.pack(side='top', fill='x',pady=15) 51 | 52 | # label and input for num1 53 | label1 = tk.Label(master=frame1, text="First Number") 54 | label1.pack(side='left') 55 | my_input1 = tk.Entry(master=frame1) 56 | my_input1.pack(side='left') 57 | 58 | # Second Number Frame2 59 | frame2 = tk.Frame(master=window) 60 | frame2.pack(side='top', fill='x',pady=15) 61 | 62 | # label and input for num1 63 | label2 = tk.Label(master=frame2, text="Second Number") 64 | label2.pack(side='left') 65 | my_input2 = tk.Entry(master=frame2) 66 | my_input2.pack(side='left') 67 | 68 | # Buttons Frame 3 69 | frame3 = tk.Frame(master=window) 70 | frame3.pack(side='top', fill='x') 71 | 72 | add_button = tk.Button(master=frame3, text=" + ", command=my_add,bg="blue",foreground="white",font=("Arial",12),width=5) 73 | add_button.pack(side='left', padx=5) 74 | 75 | sub_button = tk.Button(master=frame3, text=" - ", command=my_sub,bg="blue",foreground="white",font=("Arial",12),width=5) 76 | sub_button.pack(side='left', padx=5) 77 | 78 | mul_button = tk.Button(master=frame3, text=" * ", command=my_mul,bg="blue",foreground="white",font=("Arial",12),width=5) 79 | mul_button.pack(side='left', padx=5) 80 | 81 | div_button = tk.Button(master=frame3, text=" / ", command=my_div,bg="blue",foreground="white",font=("Arial",12),width=5) 82 | div_button.pack(side='left', padx=5) 83 | 84 | # Result 85 | result = tk.Label(master=window, text="") 86 | result.pack(side='top', fill='x') 87 | # multiplication 88 | # div_button = tk.Button(master=window, text=" / ", command=my_div,bg="blue",foreground="white",font=("Arial",12),width=5) 89 | # div_button.pack(pady=3,side='left') 90 | 91 | result = tk.Label(master=window, text="") 92 | result.pack() 93 | 94 | window.mainloop() 95 | -------------------------------------------------------------------------------- /day_17_tkinter/tkinter_beg.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | window = tk.Tk() 5 | window.title("Library Management System") 6 | window.geometry("500x500") 7 | 8 | # Label 9 | label = ttk.Label(master=window, text = "My Label") 10 | label.pack() 11 | 12 | 13 | #Input field 14 | my_input = ttk.Entry(master=window) 15 | my_input.pack() 16 | 17 | def my_add(): 18 | label.configure(text = my_input.get()) 19 | 20 | 21 | 22 | #Button 23 | add_button = ttk.Button(master= window, text = "Add", command= my_add) 24 | add_button.pack() 25 | 26 | 27 | 28 | window.mainloop() -------------------------------------------------------------------------------- /day_17_tkinter_cont/tkinter_count.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | 5 | # def addition(): 6 | # num1 = num_1_text_field.get() 7 | # num2 = num2_text_field.get() 8 | 9 | # total = int(num1) + int(num2) 10 | # result.configure(text= total) 11 | 12 | 13 | # def subtraction(): 14 | # num1 = num_1_text_field.get() 15 | # num2 = num2_text_field.get() 16 | 17 | # total = int(num1) - int(num2) 18 | # result.configure(text= total) 19 | 20 | 21 | window = tk.Tk() 22 | window.title("Calculator") 23 | window.geometry("300x200") 24 | 25 | 26 | label_1 = ttk.Label(text="First Number") 27 | label_1.pack(side= "left") 28 | 29 | num_1_text_field = ttk.Entry() 30 | num_1_text_field.pack(side="left") 31 | 32 | # num2_text_field = ttk.Entry() 33 | # num2_text_field.pack(side="left") 34 | 35 | # add_button = ttk.Button(text="Add", command= addition) 36 | # add_button.pack(side="left") 37 | 38 | # sub_button = ttk.Button(text="Subtract", command= addition) 39 | # sub_button.pack() 40 | 41 | # mul_button = ttk.Button(text="Multiply", command= addition) 42 | # mul_button.pack() 43 | 44 | # result = ttk.Label( text= "Result", font=("Arial", 40), background="red") 45 | # result.pack() 46 | 47 | window.mainloop() -------------------------------------------------------------------------------- /day_18/tkinter_grid.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | window = tk.Tk() 5 | window.title("Grid Demo") 6 | window.geometry("300x400") 7 | 8 | 9 | input_var = tk.StringVar(master=window, value="Label") 10 | 11 | entry_1 = ttk.Entry(window, textvariable=input_var ) 12 | entry_1.pack() 13 | 14 | label_1 = ttk.Label(window, text="Label 1", textvariable=input_var) 15 | label_1.pack() 16 | 17 | 18 | window.mainloop() -------------------------------------------------------------------------------- /day_19_calculator/main.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | window = tk.Tk() 5 | window.title("Calculator") 6 | window.geometry("300x400") 7 | 8 | buttons = [ 9 | "7", "8", "9", "+", 10 | "4", "5", "6", "-", 11 | "1", "2", "3", "*", 12 | "C", "0", ".", "/", 13 | "=" 14 | ] 15 | 16 | 17 | def button_handler(key): 18 | if key == "=": 19 | value = eval(entry_value.get()) 20 | entry_value.set(value) 21 | 22 | elif key == 'C': 23 | entry_value.set('0') 24 | else: 25 | entry_value.set(entry_value.get() + key) 26 | 27 | window.rowconfigure((0,1,2,3,4,5), weight=1) 28 | window.columnconfigure((0,1,2,3,4), weight=1) 29 | 30 | 31 | entry_value = tk.StringVar() 32 | 33 | entry_box = ttk.Entry(justify="right", textvariable=entry_value, font=("Arial", 20)) 34 | entry_box.grid(row=0, column=0, sticky="ewns", columnspan=4) 35 | 36 | row_count = 1 37 | col_count = 0 38 | 39 | for i in range(len(buttons)): 40 | if buttons[i] == '=': 41 | button = ttk.Button(text = buttons[i], command= lambda x = buttons[i]: button_handler(x)) 42 | button.grid(row=row_count, column=col_count, columnspan=4, sticky="ewns") 43 | else: 44 | button = ttk.Button(text=buttons[i], command= lambda x = buttons[i]: button_handler(x)) 45 | button.grid(row=row_count, column=col_count, sticky="ewns") 46 | 47 | col_count = col_count + 1 48 | if(col_count> 3): 49 | row_count = row_count + 1 50 | col_count = 0 51 | 52 | window.mainloop() -------------------------------------------------------------------------------- /day_1_installation/day_1_installation.md: -------------------------------------------------------------------------------- 1 | # Required Software/Programs 2 | - Git 3 | - Vscode 4 | - Python 5 | 6 | ## Git Installation 7 | - Git 8 | - Download Git from [here](https://git-scm.com/downloads) 9 | - Install Git 10 | 11 | ## Vscode Installation 12 | - Vscode 13 | - Download Vscode from [here](https://code.visualstudio.com/download) 14 | - Install Vscode 15 | 16 | ## Python Installation 17 | - Python 18 | - Download Python from [here](https://www.python.org/downloads/) 19 | - Install Python 20 | 21 | ## Required Vscode Extensions 22 | 23 | - [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) 24 | - [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) 25 | 26 | 27 | ## Vscode Shortcuts 28 | 29 | 30 | | Shortcut | Description | 31 | | --- | --- | 32 | | `Ctrl + Shift + P` | Open Command Palette | 33 | | `Ctrl + Shift + E` | Toggle File Explorer | 34 | | `Ctrl + Shift + X` | Toggle Extensions | 35 | | `Ctrl + B` | Toggle Side Bar | 36 | | `Ctrl + 1` | Focus on editor | 37 | | `Ctrl + ~` | Toggle Terminal | 38 | 39 | See all Vscode shortcuts from [here.](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf) 40 | 41 | -------------------------------------------------------------------------------- /day_1_installation/hello_world.py: -------------------------------------------------------------------------------- 1 | print("Hello World") -------------------------------------------------------------------------------- /day_2_print_and_variable/day_2.md: -------------------------------------------------------------------------------- 1 | # `print()` function 2 | - It is used to print the output to the screen. 3 | - It can be used to print the output of any data type. 4 | - Can be used to print multiple values at a time. 5 | - We can use `sep` and `end` parameters to change the default behaviour of the `print()` function. 6 | 7 | For Eg: 8 | 9 | ```python 10 | # prints Hello World 11 | print("Hello World") 12 | ``` 13 | 14 | ```python 15 | # prints 20 16 | a = 20 17 | print("The value of a is", a) 18 | ``` 19 | 20 | ```python 21 | # prints 22 | # Ranjit 23 | # Shrestha 24 | 25 | first_name = "Ranjit" 26 | last_name = "Shrestha" 27 | 28 | print(first_name, last_name) 29 | ``` 30 | 31 | ```python 32 | # prints 33 | # Ranjit Shrestha 34 | 35 | first_name = "Ranjit" 36 | last_name = "Shrestha" 37 | 38 | print(first_name, end=" ") 39 | print(last_name) 40 | ``` 41 | 42 | ```python 43 | # prints 44 | # Ranjit Shrestha 45 | 46 | first_name = "Ranjit" 47 | last_name = "Shrestha" 48 | 49 | print(first_name, last_name, sep=" ") 50 | ``` 51 | 52 | # Variables 53 | - Variables are used to store data. 54 | - Variables are the name attached to a value which can be changed & is used later in the code. 55 | - No need to declare variables in Python. 56 | value of the variable can be changed 57 | 58 | For Eg: 59 | 60 | ```python 61 | a = 20 62 | ``` 63 | here `a` is a label attached to the value `20`. 64 | 65 | ## Variable naming rules 66 | - Variable names can only contain letters, numbers, and underscores. 67 | - Variable names can start with a letter or an underscore, but can not start with a number. 68 | - Spaces are not allowed 69 | - Variable names are case sensitive. 70 | - Variable names should be short and descriptive, 71 | - Can not use python keywords as variable names. For eg: `print`, `if`, `else`, `for`, `while`, `True`, `False`, `None` etc. 72 | 73 | For Eg: 74 | 75 | ```python 76 | # valid variable names 77 | a = 20 78 | first_name = "Ranjit" 79 | val1 = 20 80 | _name = "Ranjit Shrestha" 81 | 82 | ``` 83 | 84 | ```python 85 | # invalid variable names 86 | 1a = 20 87 | first name = 20 88 | $abc = 20 89 | ``` 90 | 91 | ## Variable naming conventions 92 | - Use lowercase letters for variable names. 93 | - Use underscores to separate words in a variable name. 94 | - Though it is not mandatory to follow these conventions, it is a good practice to follow these conventions. 95 | 96 | For Eg: 97 | 98 | ```python 99 | first_name = "Ranjit" 100 | last_name = "Shrestha" 101 | age = 20 102 | ``` 103 | 104 | - For constant variables, use all uppercase letters. 105 | 106 | For eg: 107 | ```python 108 | PI = 3.14 109 | GRAVITY = 9.8 110 | ``` 111 | 112 | 113 | ## Python vs C variable declaration 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
C ProgramPyron
int a = 20;a = 20
float b = 20.5;b = 20.5
char c = 'a';c = 'a'
char str[] = "Hello World";str = "Hello World"
In C, we need to declare the data type of the variable.In Python, we don't need to declare the data type of the variable.
In C, we can not change the data type of the variable.In Python, we can change the data type of the variable.
In C, variable refers to the memory location.In Python, variable refers to an object not the memory location.
149 | 150 | ## Check the data type of the variable 151 | - We can use `type()` function to check the data type of the variable. 152 | 153 | For Eg: 154 | 155 | ```python 156 | a = 20 157 | print(type(a)) 158 | ``` 159 | 160 | ## Check the memory location of the variable 161 | - We can use `id()` function to check the memory location of the variable. 162 | 163 | For Eg: 164 | 165 | ```python 166 | a = 20 167 | print(id(a)) 168 | ``` 169 | 170 | -------------------------------------------------------------------------------- /day_3_data_types/data_type.md: -------------------------------------------------------------------------------- 1 | 2 | # Why do we need data types? 3 | 1. For efficient use of memory. 4 | 2. To help maintain the integrity of the data. Insures that operations are performed on data in a meaningful way and prevent unexpected behavior or errors. 5 | 3. Type checking allows a compiler to check the logic of the program before the program is actually run. For eg: `a = 10 + "Hello"` will give an error because we can not add integer and string. 6 | 4. 7 | 8 | ## Data Types in Python 9 | 1. **Numeric Data Types** - (int, float, complex) 10 | 2. **Sequence Data Types** - (str, list, tuple, range) 11 | 3. **Boolean Data Type** - (bool) 12 | 4. **Set Data Type** - (set, frozenset) 13 | 5. **Mapping Data Type** - (dict) 14 | 6. **Binary Data Type** - (bytes, bytearray, memoryview) # we will not cover this in this lecture 15 | 7. **None Data Type** - (None) 16 | 17 | 18 | ## Numeric Data Types 19 | In numeric data types, we can perform mathematical operations like addition, subtraction, multiplication, division, etc. 20 | 1. **int** - Integers are whole numbers, positive or negative, without decimals. 21 | 22 | ```python 23 | a = 10 24 | a = int(10) 25 | b = -10 26 | c = 0 27 | print(type(a)) # 28 | print(a+b) # 0 29 | print(a-b) # 20 30 | print(a*b) # -100 31 | print(a/b) # -1.0 32 | 33 | ``` 34 | 2. **float** - Floats are real numbers, with a decimal point dividing the integer and fractional parts. 35 | 36 | ```python 37 | a = 10.5 38 | b = -10.5 39 | c = 0.0 40 | 41 | n1 = float(10) 42 | print(n1) # 10.0 43 | print(type(n1)) # 44 | print(a+b) # 0.0 45 | ``` 46 | 47 | 3. **complex** - Complex numbers are written with a "j" as the imaginary part. 48 | 49 | ```python 50 | a = 10 + 5j 51 | b = -10 + 5j 52 | c = 0 + 5j 53 | 54 | n1= complex(10, 5) 55 | print(n1) # 10 + 5j 56 | print(type(n1)) # 57 | print(a+b) # 0 + 10j 58 | print(a.real) # 10.0 59 | print(a.imag) # 5.0 60 | 61 | ``` 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |
IntFloatComplex
1010.510 + 5j
-10-10.5-10 + 5j
00.00 + 5j
int(10)float(10)complex(10, 5)
92 | 93 | 94 | ## Sequence Data Types 95 | In sequence data types, we can perform operations like indexing, slicing, concatenation, repetition, etc. 96 | 1. **str** - Strings are used to store text data. Strings are immutable. 97 | 98 | ```python 99 | a = "Hello World" 100 | b = 'Hello World' 101 | c = """Hello World""" 102 | d = '''Hello World''' 103 | e = str("Hello World") 104 | 105 | print(type(a)) # 106 | print(a[0]) # H 107 | print(a[0:5]) # Hello 108 | print(a[0:5:2]) # Hlo 109 | print(a[::-1]) # dlroW olleH 110 | 111 | print(a[-4:-1]) # orl 112 | print(a[-4:]) # orld 113 | print(a[:-1]) # Hello Worl 114 | 115 | print(a[2:]) # llo World 116 | ``` 117 | 118 | ### Slice Notation 119 | - it returns a new slice object. 120 | - used in sequence data types like str, list and tuple 121 | - positive value in `step` means forward direction and negative value in `step` means backward direction. 122 | 123 | Syntax: 124 | ```python 125 | slice(start, stop, step) 126 | 127 | # or 128 | a[start:stop:step] 129 | ``` 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 |
startOptional. An integer number specifying at which position to start the slicing. Default is 0
stopAn integer number specifying at which position to end the slicing
stepOptional. An integer number specifying the step of the slicing. Default is 1
145 | 146 | -------------------------------------------------------------------------------- /day_3_data_types/data_type.py: -------------------------------------------------------------------------------- 1 | # Data types in python 2 | 3 | # 1. Numeric data types - (int, float, complex) 4 | # 2. Sequence data types - (string, list, tuple, range) 5 | # 3. Boolean data type - (bool) 6 | # 4. Set data type - (set, frozenset) 7 | # 5. Mapping Data type - (dict) 8 | # 6. Binary Data type - (bytes, bytearray, memoryview) 9 | # 7. None data type - (None) 10 | 11 | 12 | # 1. Numeric data types - (int, float, complex) 13 | 14 | # float 15 | 16 | # a = int(9) 17 | # b = float(10.1) 18 | 19 | # c = a + b 20 | # print(type(c)) 21 | 22 | # complex numbers 23 | 24 | # a = 1 + 4j 25 | # b = complex(2, 3) 26 | 27 | # c = a + b 28 | # print(c) 29 | 30 | 31 | # implicitly define values 32 | # addition, check type 33 | 34 | # Explicitly define values 35 | # addition, check type 36 | 37 | # 2. Sequence data types - (string, list, tuple, range) 38 | 39 | name = "Ranjit" 40 | # R 41 | # Ra 42 | # Ran 43 | # Ranj 44 | # Ranji 45 | # Ranjit 46 | #tijnaR -------------------------------------------------------------------------------- /day_5_data_types/data_type.md: -------------------------------------------------------------------------------- 1 | 2 | 2. **list** - Lists are used to store multiple items in a single variable. Lists are mutable. 3 | 4 | ```python 5 | a = [1, 2, 3, 4, 5] 6 | b = ["apple", "banana", "cherry"] 7 | c = [1, "apple", True, 1.5] 8 | 9 | print(type(a)) # 10 | print(a) # [1, 2, 3, 4, 5] 11 | print(a[0]) # 1 12 | print(a[0:5]) # [1, 2, 3, 4, 5] 13 | print(a[0:5:2]) # [1, 3, 5] 14 | print(a[::-1]) # [5, 4, 3, 2, 1] 15 | print(a + a) # [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] # concatenation 16 | print(a * 2) # [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] # prints list 2 times 17 | 18 | # Mutating list 19 | a[0] = 10 20 | print(a) # [10, 2, 3, 4, 5] 21 | 22 | 23 | ``` 24 | 3. **tuple** - Tuples are used to store multiple items in a single variable. Tuples are immutable. Thus it is **read only** list. 25 | 26 | ```python 27 | a = (1, 2, 3, 4, 5) 28 | b = ("apple", "banana", "cherry") 29 | c = (1, "apple", True, 1.5) 30 | 31 | print(type(a)) # 32 | print(a) # (1, 2, 3, 4, 5) 33 | print(a[0]) # 1 34 | print(a[0:5]) # (1, 2, 3, 4, 5) 35 | print(a[0:5:2]) # (1, 3, 5) 36 | print(a[::-1]) # (5, 4, 3, 2, 1) 37 | 38 | # mutating tuple 39 | a[0] = 10 # TypeError: 'tuple' object does not support item assignment 40 | ``` 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
ListTuple
[1, 2, 3, 4, 5](1, 2, 3, 4, 5)
["apple", "banana", "cherry"]("apple", "banana", "cherry")
MutableImmutable
Lists consume more memory Tuples consume less memory
65 | 66 | ## Testing memory consumption of list and tuple 67 | ```python 68 | import sys 69 | my_list = [1, 2, 3, 4, 5] 70 | my_tuple = (1, 2, 3, 4, 5) 71 | 72 | print(sys.getsizeof(my_list)) # 104 73 | print(sys.getsizeof(my_tuple)) # 88 74 | ``` 75 | 76 | 4. **range** - Range is used to store a sequence of numbers. Range is immutable. 77 | 78 | ```python 79 | a = range(10) 80 | b = range(1, 10) 81 | c = range(1, 10, 2) 82 | 83 | print(type(a)) # 84 | print(a) # range(0, 10) 85 | 86 | for i in range(10): 87 | print(i) # 0 1 2 3 4 5 6 7 8 9 88 | 89 | # range(start, stop, step) 90 | # mutating range 91 | a[0] = 10 # TypeError: 'range' object does not support item assignment 92 | ``` 93 | 94 | 95 | 96 | ## Boolean Data Type 97 | 1. **bool** - Boolean represents one of two values: True or False. 98 | 99 | ```python 100 | a = True 101 | b = False 102 | 103 | print(type(a)) # 104 | print(a) # True 105 | print(b) # False 106 | 107 | print(10 > 5) # True 108 | ``` 109 | ## Set Data Type 110 | 1. **set** - Set is used to store multiple items in a single variable. it is unordered and unindexed. Duplicate values are not allowed. It is used to perform mathematical set operations like union, intersection, etc. 111 | 112 | ```python 113 | a = {1, 2, 3, 4, 5} 114 | b = {"apple", "banana", "cherry"} 115 | c = {1, "apple", True, 1.5} 116 | 117 | print(type(a)) # 118 | print(a) # {1, 2, 3, 4, 5} 119 | print(a[0]) # TypeError: 'set' object is not subscriptable 120 | 121 | # Mutating set 122 | a.add(6) 123 | print(a) # {1, 2, 3, 4, 5, 6} 124 | 125 | # adding duplicate value 126 | a.add(6) 127 | print(a) # {1, 2, 3, 4, 5, 6} # duplicate value is not added 128 | 129 | # adding multiple values 130 | 131 | #union and intersection 132 | a = {1, 2, 3, 4, 5} 133 | b = {4, 5, 6, 7, 8} 134 | print(a.union(b)) # {1, 2, 3, 4, 5, 6, 7, 8} 135 | print(a.intersection(b)) # {4, 5} 136 | 137 | ``` 138 | 2. **frozenset** - Frozenset is used to store multiple items in a single variable. Frozenset is immutable. It is the unchangeable version of set. 139 | 140 | ```python 141 | a = frozenset({1, 2, 3, 4, 5}) 142 | b = frozenset({"apple", "banana", "cherry"}) 143 | c = frozenset({1, "apple", True, 1.5}) 144 | 145 | print(type(a)) # 146 | print(a) # frozenset({1, 2, 3, 4, 5}) 147 | print(a[0]) # TypeError: 'frozenset' object is not subscriptable 148 | ``` 149 | ## Mapping Data Type 150 | 1. **dict** - Dictionary is used to store data in key:value pairs. Dictionary is mutable. It is unordered and unindexed. 151 | 152 | ```python 153 | a = {"name": "John", "age": 36} 154 | b = {1: "apple", 2: "banana", 3: "cherry"} 155 | c = {1: "apple", "color": ["red", "green", "blue"]} 156 | 157 | my_dict = {} 158 | my_dict["name"] = "John" 159 | my_dict["age"] = 36 160 | 161 | print(my_dict) # {'name': 'John', 'age': 36} 162 | 163 | print(my_dict["name"]) # John 164 | print(my_dict.get("name")) # John 165 | 166 | print(my_dict.keys()) # prints all keys 167 | ``` 168 | 169 | ## Binary Data Type 170 | 1. **bytes** - Bytes are used to store a sequence of numbers. Bytes is immutable. 171 | 172 | ```python 173 | a = b"Hello" 174 | b = b"World" 175 | c = b"Hello World" 176 | ``` 177 | 2. **bytearray** - Bytearray are used to store a sequence of numbers. Bytearray is mutable. 178 | 179 | ```python 180 | a = bytearray(5) 181 | b = bytearray(10) 182 | c = bytearray(15) 183 | ``` 184 | 3. **memoryview** - Memoryview are used to store a sequence of numbers. Memoryview is mutable. 185 | 186 | ```python 187 | a = memoryview(bytes(5)) 188 | b = memoryview(bytes(10)) 189 | c = memoryview(bytes(15)) 190 | ``` 191 | ## None Data Type 192 | 1. **None** - None is used to define a null value, or no value at all. 193 | 194 | ```python 195 | a = None 196 | b = None 197 | c = None 198 | ``` 199 | 200 | # Mutable vs Immutable 201 | 202 | | Mutable | Immutable | 203 | | --- | --- | 204 | | Mutable objects can change their value | Immutable objects can not change their value. | 205 | | Eg: List, Set, Dictionary are mutable. |Eg: Tuple, Range, Boolean, Frozenset, Bytes, Bytearray, Memoryview, None are immutable. | 206 | 207 | # Assignemnts for strings 208 | 1. Create a variable named `name` and assign your name to it. Print the value of the variable. 209 | 210 | ```python 211 | name = "Ranjit Shrestha" 212 | print(name) 213 | ``` 214 | 215 | 2. From the variable `name`, print the first character, last character, first 3 characters, last 3 characters, and reverse of the string. 216 | 217 | ```python 218 | name = "Ranjit Shrestha" 219 | print(name[0]) # R 220 | print(name[-1]) # a 221 | print(name[0:3]) # Ran 222 | print(name[-3:]) # tha 223 | print(name[::-1]) # ahtserhS tijnaR 224 | ``` 225 | 226 | # Assignments for list 227 | 1. Create a list named `fruits` and assign 3 fruits to it. Print the value of the variable. Add 2 more fruits to the list. Print the value of the variable. Remove 1 fruit from the list. Print the value of the variable. 228 | 229 | ```python 230 | fruits = ["apple", "banana", "cherry"] 231 | print(fruits) # ['apple', 'banana', 'cherry'] 232 | 233 | fruits.append("orange") 234 | fruits.append("mango") 235 | print(fruits) # ['apple', 'banana', 'cherry', 'orange', 'mango'] 236 | 237 | fruits.remove("apple") 238 | print(fruits) # ['banana', 'cherry', 'orange', 'mango'] 239 | ``` 240 | 241 | 2. From the variable `fruits`, print the first fruit and last fruit. 242 | 243 | ```python 244 | fruits = ["apple", "banana", "cherry"] 245 | print(fruits[0]) # apple 246 | print(fruits[-1]) # cherry 247 | ``` 248 | 249 | 3. From the variable `fruits`, print the first 3 fruits, last 3 fruits, and reverse of the list. 250 | 251 | ```python 252 | fruits = ["apple", "banana", "cherry", "orange", "mango"] 253 | print(fruits[0:3]) # ['apple', 'banana', 'cherry'] 254 | print(fruits[-3:]) # ['cherry', 'orange', 'mango'] 255 | print(fruits[::-1]) # ['mango', 'orange', 'cherry', 'banana', 'apple'] 256 | ``` 257 | 258 | # Assignments for tuple 259 | 1. Create a tuple named `fruits` and assign 3 fruits to it. Print the value of the variable. Add 2 more fruits to the tuple. Print the value of the variable. Remove 1 fruit from the tuple. Print the value of the variable. 260 | 261 | ```python 262 | fruits = ("apple", "banana", "cherry") 263 | print(fruits) # ('apple', 'banana', 'cherry') 264 | 265 | fruits = fruits + ("orange", "mango") 266 | print(fruits) # ('apple', 'banana', 'cherry', 'orange', 'mango') 267 | 268 | fruits = fruits[1:] 269 | print(fruits) # ('banana', 'cherry', 'orange', 'mango') 270 | ``` -------------------------------------------------------------------------------- /day_6_control_flow/control.py: -------------------------------------------------------------------------------- 1 | i = 5 2 | 3 | while i <= 10: 4 | print(i) 5 | i = i + 1 -------------------------------------------------------------------------------- /day_6_control_flow/control_flow.md: -------------------------------------------------------------------------------- 1 | # Control Flow 2 | - By default, code is executed sequentially from top to bottom 3 | - However, such sequantial execution can only solve simple problems 4 | - Control flow statements can be used to change the order of execution of code 5 | 6 | ## Types of Control Flow 7 | - Conditional Statements 8 | - Loops 9 | 10 | 11 | ## Conditional Statements 12 | - if 13 | - if-else 14 | - if-elif-else 15 | - match (after python 3.10)- Similar to switch in other languages 16 | 17 | 18 | ## Loops 19 | - for 20 | - while 21 | 22 | 23 | ## If Conditional Statements 24 | - if statement is used to check if a condition is true or false 25 | - if the condition is true, the code inside the if block is executed 26 | - if the condition is false, the code inside the if block is skipped 27 | 28 | ### Syntax: 29 | ```python 30 | if condition: 31 | # code to be executed if condition is true 32 | ``` 33 | 34 | 35 | ### Flowchart: 36 | ![if flowchart](if.png) 37 | 38 | 39 | ### Example 1: 40 | ```python 41 | if 5 > 3: 42 | print("5 is greater than 3") 43 | ``` 44 | 45 | ### Example 2: 46 | if customer has buyed a product and amount is greater than 1000, then give 10% discount. 47 | ```python 48 | amount = 1200 49 | discount = 0 50 | if amount > 1000: 51 | discount = amount * 10 / 100 52 | 53 | print("Discount: ", discount) 54 | print("Amount to be paid: ", amount - discount) 55 | ``` 56 | 57 | ## If-else Conditional Statements 58 | - if-else statement is used to check if a condition is true or false 59 | - if the condition is true, the code inside the if block is executed 60 | - if the condition is false, the code inside the else block is executed 61 | 62 | ### Syntax: 63 | ```python 64 | if condition: 65 | # code to be executed if condition is true 66 | else: 67 | # code to be executed if condition is false 68 | ``` 69 | 70 | ### Flowchart: 71 | ![if-else flowchart](if-else.png) 72 | 73 | ### Example 1: 74 | ```python 75 | if 5 > 3: 76 | print("5 is greater than 3") 77 | else: 78 | print("5 is not greater than 3") 79 | ``` 80 | 81 | ### Example 2: 82 | if customer has buyed a product and amount is greater than 1000, then give 10% discount, else give 5% discount. 83 | ```python 84 | amount = 1200 85 | discount = 0 86 | if amount > 1000: 87 | discount = amount * 10 / 100 88 | else: 89 | discount = amount * 5 / 100 90 | 91 | print("Discount: ", discount) 92 | print("Amount to be paid: ", amount - discount) 93 | ``` 94 | 95 | 96 | ## If-elif-else Conditional Statements 97 | - if-elif-else statement is used to check if a condition is true or false 98 | - if the condition is true, the code inside the if block is executed 99 | - if the condition is false, the code inside the elif block is executed 100 | - if all the conditions are false, the code inside the else block is executed 101 | 102 | ### Syntax: 103 | ```python 104 | if condition1: 105 | # code to be executed if condition1 is true 106 | elif condition2: 107 | # code to be executed if condition2 is true 108 | elif condition3: 109 | # code to be executed if condition3 is true 110 | else: 111 | # code to be executed if all the conditions are false 112 | ``` 113 | 114 | ### Example 1: 115 | ```python 116 | marks = 80 117 | if marks >= 90: 118 | print("Grade A") 119 | elif marks >= 80: 120 | print("Grade B") 121 | elif marks >= 70: 122 | print("Grade C") 123 | elif marks >= 60: 124 | print("Grade D") 125 | else: 126 | print("Grade F") 127 | ``` 128 | 129 | ### Example 2: 130 | if customer has buyed a product and amount is greater than 1000, then give 10% discount, if amount is greater than 500, then give 5% discount, else give 2% discount. 131 | ```python 132 | amount = 1200 133 | discount = 0 134 | if amount > 1000: 135 | discount = amount * 10 / 100 136 | elif amount > 500: 137 | discount = amount * 5 / 100 138 | else: 139 | discount = amount * 2 / 100 140 | 141 | print("Discount: ", discount) 142 | print("Amount to be paid: ", amount - discount) 143 | ``` 144 | 145 | ## Match Conditional Statements 146 | - Match statement has been introduced in python 3.10 147 | - It is similar to switch statement in other languages 148 | - It is used to check if a value matches any of the given patterns 149 | - If the value matches any of the given patterns, the code inside the corresponding block is executed 150 | - If the value does not match any of the given patterns, the code inside default block is executed 151 | 152 | ### Syntax: 153 | ```python 154 | match variable: 155 | case pattern1: 156 | # code to be executed if value matches pattern1 157 | case pattern2: 158 | # code to be executed if value matches pattern2 159 | ... 160 | ... 161 | ... 162 | case patternN: 163 | # code to be executed if value matches patternN 164 | case _: 165 | # code to be executed if value does not match any of the patterns 166 | ``` 167 | 168 | ### Example 1: 169 | ```python 170 | marks = 80 171 | match marks: 172 | case 90: 173 | print("Grade A") 174 | case 80: 175 | print("Grade B") 176 | case 70: 177 | print("Grade C") 178 | case 60: 179 | print("Grade D") 180 | case _: 181 | print("Grade F") 182 | ``` 183 | 184 | ### Combined Cases: 185 | ```python 186 | user = "admin" 187 | match user: 188 | case "admin" | "superadmin": 189 | print("You have full access") 190 | case "user" | "guest": 191 | print("You have limited access") 192 | case _: 193 | print("You have no access") 194 | ``` -------------------------------------------------------------------------------- /day_6_control_flow/if-else.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_6_control_flow/if-else.png -------------------------------------------------------------------------------- /day_6_control_flow/if.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_6_control_flow/if.png -------------------------------------------------------------------------------- /day_7_control_flow/control_flow.md: -------------------------------------------------------------------------------- 1 | 2 | ## For Loops 3 | - for loop is used to iterate over a sequence such as list, tuple, set, dictionary, string, etc. 4 | 5 | ### Syntax: 6 | ```python 7 | for item in sequence: 8 | # code to be executed for each item in sequence 9 | ``` 10 | 11 | ### Flowchart: 12 | ![for loop flowchart](for-loop.png) 13 | 14 | ### Example 1 (For loop with string): 15 | ```python 16 | name = "John" 17 | for char in name: 18 | print(char) 19 | ``` 20 | 21 | ### Example 2 (For loop with list): 22 | ```python 23 | marks = [90, 80, 70, 60, 50] 24 | sum = 0 25 | for mark in marks: 26 | sum += mark 27 | 28 | print("Total marks: ", sum) 29 | ``` 30 | 31 | ### Example 3 (For loop with tuple): 32 | ```python 33 | marks = (90, 80, 70, 60, 50) 34 | sum = 0 35 | for mark in marks: 36 | sum += mark 37 | 38 | print("Total marks: ", sum) 39 | ``` 40 | 41 | ### Example 4 (For loop with set): 42 | ```python 43 | marks = {90, 80, 70, 60, 50} 44 | sum = 0 45 | for mark in marks: 46 | sum += mark 47 | 48 | print("Total marks: ", sum) 49 | ``` 50 | 51 | ### Example 5 (For loop with dictionary): 52 | ```python 53 | marks = { 54 | "Maths": 90, 55 | "Science": 80, 56 | "English": 70, 57 | "Hindi": 60, 58 | "Social Science": 50 59 | } 60 | sum = 0 61 | for subject in marks: # iterates over keys 62 | sum += marks[subject] 63 | 64 | print("Total marks: ", sum) 65 | ``` 66 | 67 | ### Example 6 (For loop with dictionary): 68 | ```python 69 | marks = { 70 | "Maths": 90, 71 | "Science": 80, 72 | "English": 70, 73 | "Hindi": 60, 74 | "Social Science": 50 75 | } 76 | 77 | print(marks.items()) # prints list of tuples 78 | 79 | # prints key and value 80 | for subject, mark in marks.items(): 81 | print(subject, mark) 82 | 83 | 84 | for item in marks: 85 | print(item) # prints key 86 | ``` 87 | 88 | 89 | ## While Loops 90 | - while loop is used to execute a block of code as long as a condition is true 91 | - The condition is checked before executing the code inside the while loop 92 | - If the condition is true, the code inside the while loop is executed 93 | 94 | ### Syntax: 95 | ```python 96 | while condition: 97 | # code to be executed if condition is true 98 | ``` 99 | 100 | ### Flowchart: 101 | ![while loop flowchart](while-loop.png) 102 | 103 | ### Example 1: 104 | ```python 105 | i = 1 106 | while i <= 5: 107 | print(i) 108 | i += 1 109 | ``` -------------------------------------------------------------------------------- /day_7_control_flow/for-loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_7_control_flow/for-loop.png -------------------------------------------------------------------------------- /day_7_control_flow/while-loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/day_7_control_flow/while-loop.png -------------------------------------------------------------------------------- /day_8_break_and_continue/break_and_continue.md: -------------------------------------------------------------------------------- 1 | 2 | # Break Statement 3 | - break statement is used to terminate a loop 4 | - It is used inside a loop 5 | - When a break statement is encountered inside a loop, the loop is terminated and the control is passed to the next statement after the loop 6 | 7 | ### Syntax: 8 | ```python 9 | while condition: 10 | # code to be executed if condition is true 11 | if condition: 12 | break 13 | ``` 14 | 15 | ### Example 1: 16 | ```python 17 | i = 1 18 | while i <= 5: 19 | print(i) 20 | if i == 3: 21 | break 22 | i += 1 23 | ``` 24 | 25 | ### Real world use case of break statement: 26 | - Search for an element in a list 27 | - If the element is found, stop searching 28 | 29 | ```python 30 | numbers = [10, 18, 21, 17, 91] 31 | search_number = 17 32 | 33 | for number in numbers: 34 | if number == search_number: 35 | print("Number found") 36 | break 37 | else: 38 | print("Number not found") 39 | ``` 40 | 41 | ### Input Validation: 42 | Continue to ask for input until the user enters a valid positive number 43 | 44 | ```python 45 | while True: 46 | number = input("Enter a positive number: ") 47 | if number.isdigit() and int(number) > 0: 48 | break 49 | else: 50 | print("Invalid input ❌. Please enter a positive number") 51 | 52 | print("The number is: ", number) 53 | ``` 54 | 55 | 56 | # Continue Statement 57 | - continue statement is used to skip the current iteration of a loop 58 | 59 | ### Syntax: 60 | ```python 61 | while condition: 62 | # code to be executed if condition is true 63 | if condition: 64 | continue 65 | ``` 66 | 67 | ### Example 1: 68 | ```python 69 | 70 | for i in range(1, 6): 71 | if i == 3: 72 | continue 73 | print(i) 74 | ``` 75 | 76 | ### Real world use case of continue statement: 77 | - Print all the odd numbers in a list 78 | 79 | ```python 80 | numbers = [10, 18, 21, 17, 91] 81 | 82 | for number in numbers: 83 | if number % 2 == 0: 84 | continue 85 | print(number) 86 | ``` 87 | 88 | # Pass Statement 89 | - pass statement is used to do nothing 90 | - It is used when a statement is required syntactically but you do not want any command or code to execute 91 | 92 | ### Syntax: 93 | ```python 94 | for i in range(1, 6): 95 | if i == 3: 96 | pass 97 | print(i) 98 | ``` 99 | 100 | ### Real world use case of pass statement: 101 | 102 | ```python 103 | for i in range(1, 6): 104 | if i == 3: 105 | pass 106 | print(i) 107 | ``` 108 | 109 | 110 | -------------------------------------------------------------------------------- /day_8_break_and_continue/break_and_continue.py: -------------------------------------------------------------------------------- 1 | def addition(a, b): 2 | print(a+b) 3 | 4 | addition(1,2) -------------------------------------------------------------------------------- /day_9_functions/functions.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | - Functions are a block of code that can be called by its name. 3 | - Functions are used to avoid repetition of code. 4 | - Functions are used to make code reusable. 5 | - Functions are used to make code modular. 6 | - Functions are used to make code readable. 7 | 8 | ## Syntax 9 | ```python 10 | def function_name(parameters): 11 | # code to be executed 12 | return 13 | ``` 14 | - def is a keyword used to define a function. 15 | - function_name is the name of the function. 16 | - () is used to pass parameters to the function. 17 | 18 | ## How to call a function? 19 | ```python 20 | def function_name(): 21 | # code to be executed 22 | 23 | function_name() 24 | ``` 25 | 26 | 27 | ## Types 28 | - Built-in functions 29 | - User-defined functions 30 | 31 | ## Built-in functions 32 | - Built-in functions are functions that are already defined in python. 33 | - Built-in functions are available in python by default. 34 | 35 | ### Examples 36 | - print() 37 | - input() 38 | - len() 39 | - type() 40 | 41 | ## How to know if a function is built-in or user-defined? 42 | - We can use the type() function to know if a function is built-in or user-defined. 43 | 44 | ```python 45 | print(type(print)) # prints 46 | ``` 47 | 48 | ```python 49 | def greet(): 50 | print("Hello") 51 | 52 | print(type(greet)) # prints 53 | ``` 54 | 55 | ## User-defined functions 56 | - User-defined functions are functions that are defined by the user. 57 | - User-defined functions are not available in python by default. 58 | - User-defined functions are defined using the def keyword. 59 | 60 | ## Types of Functional Arguments 61 | 62 | - Required arguments (positional arguments) 63 | - Keyword arguments 64 | - Default arguments 65 | - Arbitrary arguments ( *args ) 66 | - Arbitrary keyword arguments ( **kwargs ) 67 | 68 | ### Required arguments (positional arguments) 69 | 70 | - Most common type of arguments. 71 | - Values are passed to the function based on the position or order. 72 | - The number of arguments passed to the function must match the number of parameters defined in the function. 73 | 74 | ### Example 1 75 | ```python 76 | def greet(name): 77 | print("Hello", name) 78 | 79 | greet("Ranjit") ✔️ #prints value 80 | greet() ❌ #throws error 81 | ``` 82 | 83 | ### Example 2 84 | ```python 85 | def greet(name, age): 86 | print("Hello", name, "you are", age, "years old") 87 | 88 | greet("Ranjit", 20) ✔️ #prints value 89 | greet("Ranjit") ❌ #throws error 90 | greet(20, "Ranjit") ❌ #throws error 91 | ``` 92 | 93 | In Python, we can use type hints to indicate the expected types of the parameters. 94 | 95 | ```python 96 | def greet(name: str, age: int): 97 | print("Hello", name, "you are", age, "years old") 98 | 99 | greet("Ranjit", 20) ✔️ #prints value 100 | ``` 101 | --- 102 | **Note:** 103 | This is just a hint and not a constraint. We can still pass any type of value to the function. 104 | --- 105 | To make it a constraint, we can use the assert keyword. 106 | 107 | ```python 108 | def greet(name: str, age: int): 109 | assert type(name) == str, "name must be a string" 110 | assert type(age) == int, "age must be an integer" 111 | print("Hello", name, "you are", age, "years old") 112 | 113 | greet("Ranjit", 20) ✔️ #prints value 114 | ``` 115 | 116 | #### Assignment 117 | Write a function that takes two numbers as arguments and returns their sum. 118 | 119 | ```python 120 | def perform_math_operation(num1, num2, operator): 121 | if operator == '+': 122 | return num1 + num2 123 | elif operator == '-': 124 | return num1 - num2 125 | elif operator == '*': 126 | return num1 * num2 127 | elif operator == '/': 128 | # Check for division by zero 129 | if num2 != 0: 130 | return num1 / num2 131 | else: 132 | return "Error: Division by zero is not allowed." 133 | else: 134 | return "Error: Unsupported operator." 135 | 136 | result_addition = perform_math_operation(5, 3, '+') 137 | result_multiplication = perform_math_operation(4, 2, '*') 138 | result_division = perform_math_operation(8, 2, '/') 139 | 140 | ``` 141 | 142 | 143 | 144 | 145 | 146 | ### Keyword arguments 147 | 148 | - Values are passed to the function based on the parameter name. 149 | - Allows us to pass arguments in any order. 150 | - The number of arguments passed must match the number of parameters defined in the function. 151 | - This makes the code more readable. 152 | 153 | 154 | ### Example 1 155 | ```python 156 | def person(name, age): 157 | print("Hello", name, "you are", age, "years old") 158 | 159 | person(name="Ranjit", age=20) ✔️ #prints value 160 | 161 | person(age=20, name="Ranjit") ✔️ #prints value 162 | 163 | person("Ranjit", 20) ✔️ #prints value 164 | 165 | person("Ranjit", age=20) ✔️ #prints value 166 | 167 | person(name="Ranjit", 20) ❌ #throws error 168 | 169 | person(age=20, "Ranjit") ❌ #throws error 170 | ``` 171 | 172 | #### Assignment 173 | Write a function that takes two numbers as arguments and returns their sum. 174 | 175 | ```python 176 | def perform_math_operation(num1, num2, operator): 177 | if operator == '+': 178 | return num1 + num2 179 | elif operator == '-': 180 | return num1 - num2 181 | elif operator == '*': 182 | return num1 * num2 183 | elif operator == '/': 184 | # Check for division by zero 185 | if num2 != 0: 186 | return num1 / num2 187 | else: 188 | return "Error: Division by zero is not allowed." 189 | else: 190 | return "Error: Unsupported operator." 191 | 192 | result_addition = perform_math_operation(num1=5, num2=3, operator='+') 193 | 194 | 195 | -------------------------------------------------------------------------------- /day_9_functions/functions.py: -------------------------------------------------------------------------------- 1 | def person(name, age, address): 2 | print("Name:", name) 3 | print("Age:", age) 4 | print("Address:", address) 5 | 6 | 7 | person(age=25, name="Ranjit",address="Kathmandu") -------------------------------------------------------------------------------- /guiCalculator/__pycache__/graphics.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/guiCalculator/__pycache__/graphics.cpython-312.pyc -------------------------------------------------------------------------------- /guiCalculator/__pycache__/timing.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/guiCalculator/__pycache__/timing.cpython-312.pyc -------------------------------------------------------------------------------- /guiCalculator/project.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import ttk 3 | 4 | def operation(value1,value2, fakeoperator): 5 | global lastResult 6 | 7 | if(type(value1)==float or type(value1)==int and type(value2)==float or type(value2)==int ): 8 | print(value1) 9 | print(value2) 10 | print(fakeoperator) 11 | match fakeoperator: 12 | case "+": 13 | return value1 + value2 14 | case "-": 15 | return value1 - value2 16 | case "*": 17 | return value1 * value2 18 | case "/": 19 | return value1 / value2 20 | case default: 21 | return 22 | 23 | 24 | def clearButton(): 25 | global currentValue 26 | global lastResult 27 | currentValue = 0 28 | lastResult = 0 29 | screenUpdate(0) 30 | 31 | 32 | root = Tk() 33 | root.geometry("700x700") 34 | 35 | lastResult = 0 36 | currentValue = 0 37 | temporaryValue = 0 38 | operator = "" 39 | 40 | lastresultBox = ttk.Label(text="Samundra is Code God",borderwidth=5,relief='solid',foreground="gray",font=24,width=20) 41 | lastresultBox.grid(row=1,column=1,columnspan=7,pady=5) 42 | 43 | displayBox = ttk.Label(text="0",borderwidth=5,relief='solid',foreground="red",font=24,width=20) 44 | displayBox.grid(row=2,column=1,columnspan=7,pady=5) 45 | 46 | def screenUpdate(clickedValue): 47 | global currentValue 48 | currentValue = currentValue * 10 + clickedValue 49 | displayBox.configure(text=currentValue) 50 | lastresultBox.configure(text=lastResult) 51 | 52 | 53 | def EqualUpdate(): 54 | global lastResult 55 | global currentValue 56 | global operator 57 | 58 | lastResult = operation(lastResult,currentValue,operator) 59 | lastresultBox.configure(text=lastResult) 60 | 61 | currentValue = 0 62 | displayBox.configure(text=currentValue) 63 | 64 | def OperatorsClicked(sign): 65 | global operator 66 | global lastResult 67 | global currentValue 68 | 69 | if(lastResult!=0): 70 | lastResult = operation(lastResult,currentValue,operator) 71 | else: 72 | lastResult = currentValue 73 | 74 | operator = sign 75 | currentValue = 0 76 | screenUpdate(0) 77 | 78 | 79 | button1 = ttk.Button(text="1",width=5,command=lambda:screenUpdate(1)) 80 | button1.grid(row=5,column=1) 81 | button2 = ttk.Button(text="2",width=5,command=lambda:screenUpdate(2)) 82 | button2.grid(row=5,column=3) 83 | button3 = ttk.Button(text="3",width=5,command=lambda:screenUpdate(3)) 84 | button3.grid(row=5,column=5) 85 | buttonClear = ttk.Button(text="C",width=5,command=lambda:clearButton()) 86 | buttonClear.grid(row=5,column=7) 87 | 88 | button4 = ttk.Button(text="4",width=5,command=lambda:screenUpdate(4)) 89 | button4.grid(row=7,column=1) 90 | button5 = ttk.Button(text="5",width=5,command=lambda:screenUpdate(5)) 91 | button5.grid(row=7,column=3) 92 | button6 = ttk.Button(text="6",width=5,command=lambda:screenUpdate(6)) 93 | button6.grid(row=7,column=5) 94 | buttonPlus = ttk.Button(text="+",width=5, command= lambda:OperatorsClicked("+")) 95 | buttonPlus.grid(row=7,column=7) 96 | 97 | button7 = ttk.Button(text="7",width=5,command=lambda:screenUpdate(7)) 98 | button7.grid(row=9,column=1) 99 | button8 = ttk.Button(text="8",width=5,command=lambda:screenUpdate(8)) 100 | button8.grid(row=9,column=3) 101 | button9 = ttk.Button(text="9",width=5,command=lambda:screenUpdate(9)) 102 | button9.grid(row=9,column=5) 103 | buttonMultiply = ttk.Button(text="*",width=5,command=lambda:OperatorsClicked("*")) 104 | buttonMultiply.grid(row=9,column=7) 105 | 106 | button0 = ttk.Button(text="0",width=13,command=lambda:screenUpdate(0)) 107 | button0.grid(row=11,column=1,columnspan=4) 108 | buttonSubtract = ttk.Button(text="-",width=5,command= lambda:OperatorsClicked("-")) 109 | buttonSubtract.grid(row=11,column=5) 110 | buttonDivide = ttk.Button(text="/",width=5,command= lambda:OperatorsClicked("/")) 111 | buttonDivide.grid(row=11,column=7) 112 | 113 | 114 | buttonEquals = Button(text="=",foreground='red',width=5,borderwidth=2, relief="groove",command=EqualUpdate) 115 | buttonEquals.grid(row=13,column=7) 116 | 117 | 118 | 119 | root.mainloop() 120 | 121 | -------------------------------------------------------------------------------- /ipo_data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "S.N": "1", 4 | "Symbol": "SCML", 5 | "Company": "Sarbottam Cement Limited", 6 | "Units": "2,776,076.00" 7 | }, 8 | { 9 | "S.N": "2", 10 | "Symbol": "HRL", 11 | "Company": "Himalayan Reinsurance Limited", 12 | "Units": "24,900,000.00" 13 | }, 14 | { 15 | "S.N": "3", 16 | "Symbol": "NWCL", 17 | "Company": "Nepal Warehousing Company Limited", 18 | "Units": "1,141,250.00" 19 | }, 20 | { 21 | "S.N": "4", 22 | "Symbol": "MKCL", 23 | "Company": "Muktinath Krishi Company Limited", 24 | "Units": "1,148,000.00" 25 | }, 26 | { 27 | "S.N": "5", 28 | "Symbol": "VLUCL", 29 | "Company": "Vision Lumbini Urja Company Limited", 30 | "Units": "2,075,285.00" 31 | }, 32 | { 33 | "S.N": "6", 34 | "Symbol": "CKHL", 35 | "Company": "Chirkhwa Hydro Power Limited", 36 | "Units": "859,300.00" 37 | }, 38 | { 39 | "S.N": "7", 40 | "Symbol": "SONA", 41 | "Company": "Sonapur Minerals and Oil Limited", 42 | "Units": "9,732,544.00" 43 | }, 44 | { 45 | "S.N": "8", 46 | "Symbol": "MSHL", 47 | "Company": "Mid Solu Hydropower Company Limited", 48 | "Units": "621,172.00" 49 | }, 50 | { 51 | "S.N": "9", 52 | "Symbol": "MMKJL", 53 | "Company": "Mathillo Mailun Khola Jalvidhyut Limited", 54 | "Units": "1,284,200.00" 55 | }, 56 | { 57 | "S.N": "10", 58 | "Symbol": "HATHY", 59 | "Company": "Hathway Investment Nepal Limited", 60 | "Units": "2,427,750.00" 61 | }, 62 | { 63 | "S.N": "11", 64 | "Symbol": "CLI", 65 | "Company": "Citizen Life Insurance Company Limited", 66 | "Units": "9,000,000.00" 67 | }, 68 | { 69 | "S.N": "12", 70 | "Symbol": "MANDU", 71 | "Company": "Mandu Hydropower Limited", 72 | "Units": "1,205,320.00" 73 | }, 74 | { 75 | "S.N": "13", 76 | "Symbol": "BGWT", 77 | "Company": "Bhagawati Hydropower Development Company Limited", 78 | "Units": "712,220.00" 79 | }, 80 | { 81 | "S.N": "14", 82 | "Symbol": "SNLI", 83 | "Company": "Sun Nepal Life Insurance Company Limited", 84 | "Units": "7,680,000.00" 85 | }, 86 | { 87 | "S.N": "15", 88 | "Symbol": "MEHL", 89 | "Company": "Manakamana Engineering Hydropower Limited", 90 | "Units": "2,276,620.00" 91 | }, 92 | { 93 | "S.N": "16", 94 | "Symbol": "RNLI", 95 | "Company": "Reliable Nepal Life Insurance Limited", 96 | "Units": "9,600,000.00" 97 | }, 98 | { 99 | "S.N": "17", 100 | "Symbol": "ULHC", 101 | "Company": "Upper Lohore Khola Hydropower Company Limited", 102 | "Units": "1,953,279.00" 103 | }, 104 | { 105 | "S.N": "18", 106 | "Symbol": "GCIL", 107 | "Company": "Ghorahi Cement Industry Limited", 108 | "Units": "6,911,670.00" 109 | }, 110 | { 111 | "S.N": "19", 112 | "Symbol": "KBSH", 113 | "Company": "Kutheli Bukhari Small Hydropower Limited", 114 | "Units": "101,151.00" 115 | }, 116 | { 117 | "S.N": "20", 118 | "Symbol": "ILI", 119 | "Company": "IME Life Insurance Company Limited", 120 | "Units": "9,600,000.00" 121 | } 122 | ] -------------------------------------------------------------------------------- /library_management_system/__pycache__/add_book_window.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/library_management_system/__pycache__/add_book_window.cpython-312.pyc -------------------------------------------------------------------------------- /library_management_system/add_book_window.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | class AddBookWindow(tk.Toplevel): 5 | def __init__(self): 6 | super().__init__() 7 | 8 | self.title("Add Book") 9 | self.geometry("400x300") 10 | 11 | self.create_widgets() 12 | 13 | 14 | def create_widgets(self): 15 | pass -------------------------------------------------------------------------------- /library_management_system/book.py: -------------------------------------------------------------------------------- 1 | class Book: 2 | def __init__(self, title: str, author:str, ISBN:str): 3 | self.title = title 4 | self.author = author 5 | self.ISBN = ISBN 6 | 7 | def __str__(self) -> str: 8 | return f"Title:{self.title}, Author: {self.author}, ISBN: {self.ISBN} " -------------------------------------------------------------------------------- /library_management_system/library.py: -------------------------------------------------------------------------------- 1 | from book import Book 2 | from student import Student 3 | 4 | class Library: 5 | def __init__(self) -> None: 6 | self.books = [] 7 | self.students = [] 8 | 9 | 10 | def add_book(self, book: Book): 11 | self.books.append(book) 12 | 13 | def add_student(self, student: Student): 14 | self.students.append(student) -------------------------------------------------------------------------------- /library_management_system/main.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | from add_book_window import AddBookWindow 4 | 5 | class LibrarySystem(tk.Tk): 6 | def __init__(self): 7 | super().__init__() 8 | self.title("Library Management System") 9 | self.geometry("900x600") 10 | self.create_widgets() 11 | 12 | def create_widgets(self): 13 | add_book_button = ttk.Button(master=self, text="Add Book", command=self.show_add_book) 14 | add_book_button.pack(anchor="w", padx= 20, pady=20) 15 | 16 | book_tree = ttk.Treeview(master= self, columns=( 'name', 'author', 'isbn'), show='headings') 17 | book_tree.heading('name', text= 'Full Name', anchor='w') 18 | book_tree.heading('author', text= 'Author Name', anchor='w') 19 | book_tree.heading('isbn', text= 'ISBN', anchor='w') 20 | book_tree.pack(anchor='w', padx= 20, pady=20) 21 | 22 | book_tree.insert(parent='', index= tk.END, values=("ram", 'Shyam', '2332')) 23 | 24 | def show_add_book(self): 25 | AddBookWindow() 26 | 27 | 28 | library = LibrarySystem() 29 | library.mainloop() 30 | 31 | 32 | 33 | 34 | # add_student_button = ttk.Button(master=root, text= "Add Student") 35 | # add_student_button.pack(anchor="w", padx=20, pady=20) 36 | 37 | # student_tree = ttk.Treeview(master= root, columns=('S.N', 'Name', 'Email', 'Phone', 'Address')) 38 | # student_tree.heading('S.N', text='S.N' , anchor="w") 39 | # student_tree.heading('Name', text='Name') 40 | # student_tree.heading('Email', text='Email') 41 | # student_tree.heading('Phone', text='Phone') 42 | # student_tree.heading('Address', text='Address') 43 | # student_tree.pack(padx= 20, pady= 20) 44 | 45 | # root.mainloop() -------------------------------------------------------------------------------- /library_management_system/student.py: -------------------------------------------------------------------------------- 1 | class Student: 2 | def __init__(self, name, email, phone, address) -> None: 3 | self.name = name 4 | self.email = email 5 | self.phone = phone 6 | self.address = address 7 | 8 | def __str__(self) -> str: 9 | return f"{self.name} {self.email} {self.phone} {self.address}" 10 | 11 | -------------------------------------------------------------------------------- /mahendra/calc.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | 3 | def button_click(number): 4 | current = entry.get() 5 | entry.delete(0, tk.END) 6 | entry.insert(0, str(current) + str(number)) 7 | 8 | def button_clear(): 9 | entry.delete(0, tk.END) 10 | 11 | def button_add(): 12 | first_number = entry.get() 13 | global f_num 14 | global math_operation 15 | math_operation = "addition" 16 | f_num = float(first_number) 17 | entry.delete(0, tk.END) 18 | 19 | def button_subtract(): 20 | first_number = entry.get() 21 | global f_num 22 | global math_operation 23 | math_operation = "subtraction" 24 | f_num = float(first_number) 25 | entry.delete(0, tk.END) 26 | 27 | def button_multiply(): 28 | first_number = entry.get() 29 | global f_num 30 | global math_operation 31 | math_operation = "multiplication" 32 | f_num = float(first_number) 33 | entry.delete(0, tk.END) 34 | 35 | def button_divide(): 36 | first_number = entry.get() 37 | global f_num 38 | global math_operation 39 | math_operation = "division" 40 | f_num = float(first_number) 41 | entry.delete(0, tk.END) 42 | 43 | def button_equal(): 44 | second_number = entry.get() 45 | entry.delete(0, tk.END) 46 | 47 | if math_operation == "addition": 48 | entry.insert(0, f_num + float(second_number)) 49 | elif math_operation == "subtraction": 50 | entry.insert(0, f_num - float(second_number)) 51 | elif math_operation == "multiplication": 52 | entry.insert(0, f_num * float(second_number)) 53 | elif math_operation == "division": 54 | entry.insert(0, f_num / float(second_number)) 55 | 56 | # Create the main window 57 | root = tk.Tk() 58 | root.title("CALCULATOR") 59 | 60 | # Entry widget to display the input and result 61 | entry = tk.Entry(root, width=16, font=('Arial', 18), borderwidth=5) 62 | entry.grid(row=0, column=0, columnspan=4, padx=10, pady=10) 63 | 64 | # Define buttons 65 | buttons = [ 66 | ('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3), 67 | ('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3), 68 | ('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3), 69 | ('0', 4, 0), ('C', 4, 1), ('=', 4, 2), ('+', 4, 3) 70 | ] 71 | 72 | # Create and place buttons on the grid 73 | for (text, row, column) in buttons: 74 | button = tk.Button(root, text=text, padx=20, pady=20, font=('Arial', 16), 75 | command=lambda t=text: button_click(t) if t.isnumeric() or t == '.' else button_clear() if t == 'C' else button_equal() if t == '=' else button_add() if t == '+' else button_subtract() if t == '-' else button_multiply() if t == '*' else button_divide()) 76 | button.grid(row=row, column=column) 77 | 78 | # Run the main loop 79 | root.mainloop() 80 | -------------------------------------------------------------------------------- /project-1/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Project-1: To-Do (command-line) app 3 | 4 | ## [Note] 5 | 6 | Before attempting this project, ensure that you have a basic understanding of Python syntax, variables, data types, and all the topics covered in the Python training class. 7 | 8 | ## Functions: 9 | 10 | 1. **Add Task** 11 | 2. **View Task** 12 | 3. **Mark as Completed** 13 | 4. **Remove Task** 14 | 15 | ## Steps: 16 | 17 | ### 1. Initialize the To-Do List 18 | 19 | ### 2. Display Menu Options 20 | 21 | Show the user a menu of options they can perform on the to-do list (add task, mark as completed, view tasks, remove task, exit). 22 | 23 | ### 3. Get User Input 24 | 25 | Prompt the user to choose an action from the menu. 26 | 27 | ### 4. Implement Actions Based on User Input 28 | 29 | #### 4.1 Add Task 30 | 31 | - Ask the user to input a new task. 32 | - Append this task to the to-do list. 33 | 34 | #### 4.2 Mark as Completed 35 | 36 | - Ask the user for the task number they want to mark as completed. 37 | - Update the corresponding task's completion status to `True`. 38 | 39 | #### 4.3 View Tasks 40 | 41 | - Display all tasks in the to-do list along with their completion status. 42 | 43 | #### 4.4 Remove Task 44 | 45 | - Ask the user for the task number they want to remove. 46 | - Remove the specified task from the to-do list. 47 | 48 | #### 4.5 Exit 49 | 50 | - Allow the user to exit the program when they are done managing their to-do list. 51 | 52 | Happing Learning!! -------------------------------------------------------------------------------- /project-1/final/index.py: -------------------------------------------------------------------------------- 1 | # Initialize the to-do list 2 | # all the list are stored in this list 3 | todo_list = [] 4 | 5 | # we want this loop to run until the user want 6 | # then we also have to create logic to stop the loop 7 | 8 | 9 | while True: 10 | # Display menu options 11 | print("\nTo-Do List Manager") 12 | print("1. Add Task") 13 | print("2. Mark as Completed") 14 | print("3. View Tasks") 15 | print("4. Remove Task") 16 | print("5. Exit") 17 | 18 | 19 | 20 | # Get user choice 21 | choice = input("Enter your choice (1-5): ") 22 | 23 | 24 | 25 | # user will press any number from 1-5: 26 | # based on the user's choice following block will be executed 27 | 28 | if choice == "1": 29 | # Add Task 30 | task = input("Enter a new task: ") 31 | todo_list.append({"task": task, "completed": False}) 32 | 33 | 34 | elif choice == "2": 35 | # Mark as Completed 36 | task_index = int(input("Enter the task number to mark as completed: ")) 37 | 38 | #user enters the number/index of the task to mark the task as completed 39 | 40 | if task_index >=0 and task_index < len(todo_list): 41 | # the index user enters should be greater than 0 and less than the length of the list 42 | 43 | # in python we can write this line of code like this 44 | # if 0 <= task_index and task_index < len(todo_list) 45 | # whatever you refer , you can do it 46 | 47 | todo_list[task_index]["completed"] = True 48 | else: 49 | print("Invalid task number.") 50 | 51 | 52 | elif choice == "3": 53 | # View Tasks 54 | # in one of the class we learned enumerate() it de-struct/returns index and task 55 | # example below.... 56 | 57 | for index, task in enumerate(todo_list): 58 | print(f"{index}: {task['task']} - {'Completed' if task['completed'] else 'Not Completed'}") 59 | # This line displays the index, task description, and completion status 60 | 61 | 62 | 63 | elif choice == "4": 64 | # Remove Task 65 | task_index = int(input("Enter the task number to remove: ")) 66 | if task_index >=0 and task_index < len(todo_list): 67 | removed_task = todo_list.pop(task_index) 68 | print(f"Removed task: {removed_task['task']}") 69 | else: 70 | print("Invalid task number.") 71 | 72 | 73 | elif choice == "5": 74 | # Exit 75 | print("Exiting the To-Do List Manager. Goodbye!") 76 | break 77 | else: 78 | print("Invalid choice. Please enter a number between 1 and 5.") 79 | 80 | 81 | 82 | 83 | # demo_list = ["Learn py", "Go to tour", "Shopping", "Learn c#"] 84 | 85 | # # enumerate method returns the index and task 86 | # # you can learn unpacking concept 87 | 88 | 89 | # for index, task in enumerate(demo_list): 90 | # print(f"Task {index + 1}: {task}") 91 | 92 | -------------------------------------------------------------------------------- /project-1/starter/app.py: -------------------------------------------------------------------------------- 1 | #let's go.. -------------------------------------------------------------------------------- /project-2/final/index.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess_the_number(difficulty): 4 | match difficulty: 5 | 6 | # user picks the difficulty 7 | # based on difficulty choosed by the users, value are assigned 8 | 9 | case "easy": 10 | lower_bound, upper_bound, max_attempts = 1, 20, 5 11 | case "medium": 12 | lower_bound, upper_bound, max_attempts = 1, 50, 8 13 | case "hard": 14 | lower_bound, upper_bound, max_attempts = 1, 100, 10 15 | case _: 16 | print("Invalid difficulty level. Please choose from easy, medium, or hard.") 17 | return 18 | 19 | 20 | 21 | #this line of generates the random number 22 | target_number = random.randint(lower_bound, upper_bound) 23 | attempts = 0 24 | 25 | print(f"Welcome to Guess the Number ({difficulty.capitalize()} level)!") 26 | print(f"You have {max_attempts} to guess the number") 27 | 28 | while attempts < max_attempts: 29 | 30 | user_guess = int(input(f"Guess the number between {lower_bound} and {upper_bound}: ")) 31 | attempts += 1 32 | 33 | if user_guess < target_number: 34 | print("Too low! Try again.") 35 | elif user_guess > target_number: 36 | print("Too high! Try again.") 37 | else: 38 | print(f"Congratulations! You guessed the number {target_number} in {attempts} attempts.") 39 | return 40 | 41 | print(f"Sorry, you've used all {max_attempts} attempts. The number was {target_number}.") 42 | 43 | # Choose difficulty level 44 | difficulty_level = input("Choose difficulty level (easy, medium, hard): ") 45 | guess_the_number(difficulty_level.lower()) 46 | 47 | -------------------------------------------------------------------------------- /project-2/readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Guess the Number Game 3 | 4 | ## Overview 5 | This is a simple command-line game where it generates a random number, and the user tries to guess it. The game offers different difficulty levels, limited attempts, and occasional hints. 6 | 7 | ## Steps 8 | 1. Choose a difficulty level: easy, medium, or hard. 9 | 2. Guess the number between the specified range. 10 | 3. Receive feedback on whether your guess is too low, too high, or correct. 11 | 4. Try to guess the number within the allowed attempts. 12 | 6. View your score upon guessing the correct number. 13 | 14 | ## Note 15 | Multiple assignment,tuple unpacking 16 | Learn here https://www.pythontutorial.net/python-basics/python-unpacking-tuple/ 17 | 18 | -------------------------------------------------------------------------------- /project-2/starter/index.py: -------------------------------------------------------------------------------- 1 | # lets go.. -------------------------------------------------------------------------------- /project-3/Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-3/Screenshot1.png -------------------------------------------------------------------------------- /project-3/Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-3/Screenshot2.png -------------------------------------------------------------------------------- /project-3/final/index.py: -------------------------------------------------------------------------------- 1 | print("--------------------TIC TAC TOE--------------------") 2 | # creates the board 3 | def print_board(board): 4 | for row in board: 5 | for cell in row: 6 | print(cell, end=" | ") 7 | print("\n" + "-" * 13) 8 | 9 | def check_winner(board, player): 10 | # Check rows and columns 11 | for i in range(3): 12 | # checking for a win in either a row or a column 13 | if all(board[i][j] == player for j in range(3)) or all(board[j][i] == player for j in range(3)): 14 | return True 15 | 16 | # Check for a win (diagonals) 17 | if all(board[i][i] == player for i in range(3)) or all(board[i][2 - i] == player for i in range(3)): 18 | return True 19 | 20 | return False 21 | 22 | def is_board_full(board): 23 | return all(board[i][j] != ' ' for i in range(3) for j in range(3)) 24 | 25 | def initialize_board(): 26 | board = [] 27 | for _ in range(3): 28 | row = [] 29 | for _ in range(3): 30 | row.append(' ') 31 | board.append(row) 32 | return board 33 | 34 | def play_tic_tac_toe(): 35 | board = initialize_board() 36 | current_player = 'X' 37 | 38 | while True: 39 | print_board(board) 40 | row = int(input(f"Player {current_player}, enter row (0, 1, 2): ")) 41 | col = int(input(f"Player {current_player}, enter column (0, 1, 2): ")) 42 | 43 | if board[row][col] == ' ': 44 | board[row][col] = current_player 45 | else: 46 | print("Cell already occupied. Try again.") 47 | continue 48 | 49 | if check_winner(board, current_player): 50 | print_board(board) 51 | print(f"Player {current_player} wins!") 52 | break 53 | elif is_board_full(board): 54 | print_board(board) 55 | print("It's a tie!") 56 | break 57 | 58 | if current_player == 'X': 59 | current_player = 'O' 60 | else: 61 | current_player = 'X' 62 | 63 | play_tic_tac_toe() -------------------------------------------------------------------------------- /project-3/readme.md: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe Game 2 | 3 | ## Overview 4 | This is a console-based Tic-Tac-Toe game implemented in Python. Players take turns to make moves on a 3x3 grid, aiming to get three of their symbols in a row, column, or diagonal. 5 | 6 | ## Features 7 | - 3x3 grid for gameplay. 8 | - Two players (X and O) taking turns entering their moves by specifying the row and column (0, 1, 2). 9 | - Checks for a winner after each move. 10 | - Ends in a tie if the board is full. 11 | 12 | ##Screenshot 13 | 14 | ![Tic-Tac-Toe Screenshot](Screenshot1.png) 15 | ![Tic-Tac-Toe Screenshot](Screenshot2.png) -------------------------------------------------------------------------------- /project-3/starter/index.py: -------------------------------------------------------------------------------- 1 | # let's go... 2 | -------------------------------------------------------------------------------- /project-4/Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-4/Screenshot1.png -------------------------------------------------------------------------------- /project-4/Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-4/Screenshot2.png -------------------------------------------------------------------------------- /project-4/final/app.py: -------------------------------------------------------------------------------- 1 | class Book: 2 | def __init__(self, title, author): 3 | # private properties 4 | self.__title = title 5 | self.__author = author 6 | self.__available = True 7 | 8 | def get_title(self): 9 | return self.__title 10 | 11 | def get_author(self): 12 | return self.__author 13 | 14 | def is_available(self): 15 | return self.__available 16 | 17 | def borrow(self): 18 | if self.__available: 19 | print(f"Book '{self.__title}' by {self.__author} has been borrowed.") 20 | self.__available = False 21 | else: 22 | print(f"Sorry, '{self.__title}' is currently not available.") 23 | 24 | def return_book(self): 25 | if not self.__available: 26 | print(f"Book '{self.__title}' has been returned.") 27 | self.__available = True 28 | else: 29 | print(f"This book is already in the library.") 30 | 31 | def __str__(self): 32 | status = "Available" if self.__available else "Not Available" 33 | return f"{self.__title} by {self.__author} - Status: {status}" 34 | 35 | 36 | 37 | 38 | class Library: 39 | def __init__(self): 40 | self.books = {} 41 | 42 | def add_book(self, book): 43 | title = book.get_title() 44 | if title not in self.books: 45 | self.books[title] = book 46 | print(f"Book '{title}' added to the library.") 47 | else: 48 | print(f"Book '{title}' is already in the library.") 49 | 50 | def display_books(self): 51 | if not self.books: 52 | print("No books in the library.") 53 | else: 54 | print("Books in the library:") 55 | for book in self.books.values(): 56 | print(book) 57 | 58 | 59 | 60 | library = Library() 61 | 62 | while True: 63 | print("\n1. Add Book\n2. Borrow Book\n3. Return Book\n4. Display Books\n5. Exit") 64 | choice = input("Enter your choice: ") 65 | 66 | if choice == "1": 67 | title = input("Enter book title: ") 68 | author = input("Enter author name: ") 69 | new_book = Book(title, author) 70 | library.add_book(new_book) 71 | 72 | elif choice == "2": 73 | title = input("Enter the title of the book you want to borrow: ") 74 | if title in library.books: 75 | library.books[title].borrow() 76 | else: 77 | print(f"Book '{title}' not found in the library.") 78 | 79 | elif choice == "3": 80 | title = input("Enter the title of the book you want to return: ") 81 | if title in library.books: 82 | library.books[title].return_book() 83 | else: 84 | print(f"Book '{title}' not found in the library.") 85 | 86 | elif choice == "4": 87 | library.display_books() 88 | 89 | elif choice == "5": 90 | print("Thankyou,see you again.") 91 | break 92 | 93 | else: 94 | print("Invalid choice. Please enter a valid option.") -------------------------------------------------------------------------------- /project-4/readme.md: -------------------------------------------------------------------------------- 1 | # Library Management System 2 | 3 | This project is a simple library management system implemented in Python. It allows users to add books to the library, borrow and return books, and display the current list of books in the library. 4 | 5 | 6 | [Note]: This is project to practice the fundamental oop in python we've learned so far ie: classes, object,access modifier 7 | 8 | ## Classes 9 | 10 | ### `Book` 11 | 12 | The `Book` class represents a book in the library. It has the following attributes and methods: 13 | 14 | - **Attributes:** 15 | - Title of the book (private) 16 | - Author of the book (private) 17 | - Availability status of the book (private) 18 | 19 | - **Methods:** 20 | - `get_title()` 21 | - `get_author()` 22 | - `is_available()` 23 | - `borrow()` 24 | - `return_book()` 25 | 26 | - **Magic Method:** 27 | - `__str__()` 28 | 29 | ### `Library` 30 | 31 | The `Library` class manages a collection of books. 32 | 33 | ## Features 34 | 35 | 1. **Add Book** 36 | 37 | 2. **Borrow Book** 38 | 39 | 3. **Return Book** 40 | 41 | 4. **Display Books** 42 | 43 | 5. **Exit** 44 | 45 | ## Screenshot 46 | ![Library Screenshot](Screenshot1.png) 47 | ![Library Screenshot](Screenshot2.png) 48 | 49 | 50 | -------------------------------------------------------------------------------- /project-4/starter/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-4/starter/app.py -------------------------------------------------------------------------------- /project-5-calc/app.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | 4 | class Calculator: 5 | def __init__(self, root): 6 | self.root = root 7 | self.root.title("Calculator") 8 | self.root.geometry("300x410") 9 | self.root.resizable(0, 0) 10 | 11 | self.result_var = tk.StringVar() 12 | self.result_entry = ttk.Entry(root, textvariable=self.result_var, font=('Arial', 14), justify='right') 13 | self.result_entry.grid(row=0, column=0, columnspan=4, sticky='nsew') 14 | 15 | buttons = [ 16 | '%', 'CE', 'C', '⇐', 17 | '1/x', 'x^2', '√x', '÷', 18 | '7', '8', '9', '*', 19 | '4', '5', '6', '-', 20 | '1', '2', '3', '+', 21 | '+/-', '0', '.', '=' 22 | ] 23 | 24 | for i in range(6): 25 | self.root.grid_rowconfigure(i, weight=1) 26 | self.root.grid_columnconfigure(i, weight=1) 27 | 28 | row_val = 1 29 | col_val = 0 30 | for button in buttons: 31 | ttk.Button(root, text=button, command=lambda b=button: self.on_button_click(b)).grid(row=row_val, column=col_val, sticky='nsew') 32 | col_val += 1 33 | if col_val > 3: 34 | col_val = 0 35 | row_val += 1 36 | 37 | self.root.bind('', lambda event: self.on_button_click('=')) 38 | 39 | def on_button_click(self, button): 40 | current_text = self.result_var.get() 41 | 42 | if button == '⇐': 43 | self.result_var.set(current_text[:-1]) 44 | elif button == 'CE': 45 | self.result_var.set('') 46 | elif button == 'C': 47 | self.result_var.set('') 48 | elif button == '=': 49 | try: 50 | result = eval(current_text) 51 | self.result_var.set(str(result)) 52 | except Exception as e: 53 | self.result_var.set('Error') 54 | elif button == '+/-': 55 | if current_text and current_text[0] == '-': 56 | self.result_var.set(current_text[1:]) 57 | else: 58 | self.result_var.set('-' + current_text) 59 | elif button == '1/x': 60 | try: 61 | result = 1 / float(current_text) 62 | self.result_var.set(str(result)) 63 | except ZeroDivisionError: 64 | self.result_var.set('Error') 65 | elif button == 'x^2': 66 | self.result_var.set(str(float(current_text) ** 2)) 67 | elif button == '√x': 68 | try: 69 | result = float(current_text) ** 0.5 70 | self.result_var.set(str(result)) 71 | except ValueError: 72 | self.result_var.set('Error') 73 | else: 74 | self.result_var.set(current_text + button) 75 | 76 | root = tk.Tk() 77 | app = Calculator(root) 78 | root.mainloop() 79 | 80 | -------------------------------------------------------------------------------- /project-5-calc/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-5-calc/img.png -------------------------------------------------------------------------------- /project-5-calc/readme.md: -------------------------------------------------------------------------------- 1 | # Calculator App with Tkinter 2 | 3 | This is a simple calculator application built using Python's Tkinter library. 4 | 5 | ## Features 6 | 7 | - Arithmetic operations: Addition, Subtraction, Multiplication, Division 8 | - Additional functions: Percentage, Square, Square Root, Inverse 9 | - Backspace feature (⇐) to remove the last entered character 10 | - Decimal point (.) for floating-point numbers 11 | 12 | ## Keyboard Event 13 | 14 | - `Enter`: Calculate result ,you can pres enter instead of = button 15 | 16 | ### How Keyboard Events are Handled 17 | 18 | we use a feature in Tkinter called the bind method to handle keyboard events. We use it to connect the 'Enter' key to a specific action in our calculator. 19 | Example : 20 | 21 | ```python 22 | self.root.bind('', lambda event: self.on_button_click('=')) 23 | ``` 24 | 25 | This line of code means that when the user presses the 'Enter' key, it's like they clicked the '=' button on the calculator. 26 | 27 | ## Features 28 | 29 | - **Tkinter Widgets**: Utilizes Tkinter's Entry and Button widgets for the user interface. 30 | - **Event Handling**: Responds to button clicks and keyboard events, such as the 'Enter' key. 31 | - **Grid Layout**: Configures rows and columns for proper grid-based layout, enhancing the responsiveness of the calculator. 32 | 33 | ## Screenshots 34 | 35 | ![Alt Text](./img.png) 36 | -------------------------------------------------------------------------------- /project-6-dictionary/Readme.md: -------------------------------------------------------------------------------- 1 | #Dictionary App 2 | 3 | The Dictionary App is a simple desktop application built using Python and the Tkinter library. 4 | 5 | ##Features 6 | 7 | - Search for Definitions: Enter a word in the input field and click the "Search" button to fetch its definitions from an external API. 8 | 9 | - Display Meanings: The app displays the meanings of the entered word, including the part of speech and definition. 10 | 11 | ##Dependencies 12 | Tkinter: Used for creating the graphical user interface. 13 | 14 | ttkbootstrap: Provides additional styles for Tkinter widgets, it is similar to the bootstrap used for styling HTML. 15 | 16 | Requests: Used to make HTTP requests to the external dictionary API. 17 | 18 | #Acknowledgments 19 | The app uses the [Dictionary API](https://dictionaryapi.dev/) to fetch word definitions. 20 | 21 | 22 | 23 | #Screen Shot 24 | ![Screenshot of the Dictionary App](./p1.png) 25 | -------------------------------------------------------------------------------- /project-6-dictionary/app.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from ttkbootstrap import Style,ttk 3 | import requests 4 | 5 | 6 | def get_definition(word): 7 | response = requests.get(f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}") 8 | if response.status_code == 200: 9 | data = response.json() 10 | if data: 11 | meanings = data[0]['meanings'] 12 | definitions = [] 13 | for meaning in meanings: 14 | definitions.append(f"Meaning: {meaning['partOfSpeech']}\nDefinition: {meaning['definitions'][0]['definition']}\n") 15 | return '\n'.join(definitions) 16 | return "No Definition found." 17 | 18 | 19 | 20 | def search_definition(): 21 | word = entry_word.get() 22 | definition = get_definition(word) 23 | text_output.configure(state='normal') 24 | text_output.delete('1.0',tk.END) 25 | text_output.insert(tk.END,definition) 26 | text_output.configure(state='disabled') 27 | 28 | 29 | root = tk.Tk() 30 | style= Style(theme="flatly") 31 | root.title("Dictionary") 32 | root.geometry("500x300") 33 | 34 | 35 | frame_search = ttk.Frame(root) 36 | frame_search.pack(padx=20,pady=20) 37 | 38 | 39 | label_word = ttk.Label(frame_search, 40 | text='Enter a word:', 41 | font=('TkDefaultFont',15,'bold')) 42 | label_word.grid(row=0,column=0,padx=5,pady=5) 43 | 44 | 45 | entry_word =ttk.Entry(frame_search,width=20,font=('TkDefaultFont',15)) 46 | entry_word.grid(row=0,column=1,padx=5,pady=5) 47 | 48 | button_search = ttk.Button(frame_search,text="Search",command=search_definition) 49 | button_search.grid(row=0,column=2,padx=5,pady=5) 50 | 51 | 52 | frame_output = ttk.Frame(root) 53 | frame_output.pack(padx=20,pady=10) 54 | 55 | text_output = tk.Text(frame_output,height=10,state='disabled',font=('TkDefaultFont',15)) 56 | text_output.pack() 57 | 58 | 59 | root.mainloop() -------------------------------------------------------------------------------- /project-6-dictionary/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-6-dictionary/p1.png -------------------------------------------------------------------------------- /project-7-selenium-todo-automation/Readme.md: -------------------------------------------------------------------------------- 1 | # Selenium Todo List Automation 2 | 3 | This Selenium script automates the actions on a Todo list application found at https://example.cypress.io/todo#/completed. The script adds new todos, marks them as completed, and then clears the completed todos. 4 | 5 | ## Explanation 6 | 7 | - The script uses Selenium WebDriver to automate actions on the Todo list application. 8 | - It opens the application in a Chrome browser. 9 | - Waits for 1 second to ensure the page is loaded. 10 | - Adds new todos "Learn python", "Create a project", and "Master the python full stack". 11 | - Marks the third, fourth, and fifth todos as completed. 12 | - Clears the completed todos. 13 | - Handles exceptions and closes the browser afterward. 14 | 15 | ## Methods Used 16 | 17 | - `webdriver.Chrome()`: Initializes a Chrome WebDriver instance. 18 | - `driver.get(url)`: Navigates to the specified URL. 19 | - `time.sleep(seconds)`: Pauses execution for the specified number of seconds. 20 | - `find_element(By.CLASS_NAME, class_name)`: Finds the first element matching the specified class name. 21 | - `find_elements(By.CLASS_NAME, class_name)`: Finds all elements matching the specified class name. 22 | - `find_element(By.XPATH, xpath)`: Finds the first element matching the specified XPath expression. 23 | - `element.click()`: Simulates a mouse click on the element. 24 | - `ActionChains(driver)`: Instantiates an ActionChains object for performing keyboard and mouse actions. 25 | - `send_keys(keys)`: Sends keys to the current focused element. 26 | - `key_down(Keys.ENTER)`: Sends an Enter key press event. 27 | - `quit()`: Closes the browser and terminates the WebDriver session. 28 | 29 | ## References 30 | 31 | - Selenium WebDriver Documentation: [https://www.selenium.dev/documentation/en/](https://www.selenium.dev/documentation/en/) 32 | 33 | ### Todo List Application 34 | 35 | - Original source: [Cypress Example TodoMVC](https://example.cypress.io/) 36 | 37 | ## Screenshots 38 | 39 | ![Todo List Application Screenshot](todo.png) 40 | -------------------------------------------------------------------------------- /project-7-selenium-todo-automation/todo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rgtstha/BCA-Python-Training/809c5a4b0d509882bab1ee643b07264a587663a5/project-7-selenium-todo-automation/todo.png -------------------------------------------------------------------------------- /project-7-selenium-todo-automation/todo.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver import Keys,ActionChains 4 | import time 5 | 6 | 7 | try: 8 | driver = webdriver.Chrome() 9 | driver.get("https://example.cypress.io/todo#/completed") 10 | time.sleep(1) 11 | 12 | todo = driver.find_element(By.CLASS_NAME,"new-todo") 13 | todos = ["Learn python", "Create a project", "Master the python full stack"] 14 | for todo in todos: 15 | ActionChains(driver).send_keys(todo).perform() 16 | time.sleep(1) 17 | ActionChains(driver).key_down(Keys.ENTER).perform() 18 | time.sleep(1) 19 | 20 | time.sleep(1) 21 | 22 | all_link = driver.find_element(By.XPATH, '//a[text()="All"]') 23 | all_link.click() 24 | time.sleep(1) 25 | 26 | destroy_buttons = driver.find_elements(By.CLASS_NAME, "toggle") 27 | third_destroy_button = destroy_buttons[2] 28 | third_destroy_button.click() 29 | time.sleep(1) 30 | 31 | fourth_destroy_button = destroy_buttons[3] 32 | fourth_destroy_button.click() 33 | time.sleep(1) 34 | 35 | five_destroy_button = destroy_buttons[4] 36 | five_destroy_button.click() 37 | time.sleep(1) 38 | 39 | 40 | clear_completed_button = driver.find_element(By.CLASS_NAME, "clear-completed") 41 | clear_completed_button.click() 42 | time.sleep(1) 43 | 44 | 45 | except Exception as e: 46 | print(e) 47 | 48 | finally: 49 | driver.quit() 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # BCA Python Training 2 | 3 | ## Table of Contents 4 | 1. [Day 1- Installation](./day1_installation/day_1_installation.md) 5 | 2. [Day 2- Print Function and Variables](./day2_print_and_variable/day_2.md) 6 | 3. [Day 3- Data Types](./day3_data_types/data_type.md) 7 | 4. Revised day 1, 2 and 3 8 | 5. [Day 5 - Data Types Continued](./day5_data_types/data_type.md) 9 | 6. [Day 6 - Control Flow](./day_6_control_flow/control_flow.md) 10 | 7. [Day 7 - Control Flow Continued](./day_7_control_flow/control_flow.md) 11 | 8. [Day 8 - Break and Continue](./day_8_break_and_continue/break_and_continue.md) 12 | 9. [Day 9 - Functions](./day_9_functions/functions.md) 13 | 10. [Day 10- Functions Continued](./day_10_functions_continue/function.md) 14 | 11. [Day 11- Class](./day_11_class/note.md) 15 | 12. [Day 12 - Class Continue](./day_12_class_continue/class_continue.md) 16 | 13. [Day 13 - Class Continue](./day_13_class_cont/class_continue.md) 17 | 14. [Day 14 - Class Continue](./day_14/modules.md) 18 | 15. [Day 15 - Abstraction](./day_15_abstraction/abstraction.md) 19 | 16. [Day 16 - Packages](./day_16/packages.md) 20 | 17. [Day 17 - Tkinter](./day_17_tkinter/gui_application.md) -------------------------------------------------------------------------------- /selenium/abc.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | 's.n': 1, 4 | 'Symbol': 'SCML', 5 | }, 6 | { 7 | 's.n': 1, 8 | 'Symbol': 'SCML', 9 | } 10 | ] -------------------------------------------------------------------------------- /selenium/automate.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | # chrome_options = webdriver.ChromeOptions() 6 | # chrome_options.add_argument('--headless') 7 | 8 | driver = webdriver.Chrome() 9 | driver.get('http://the-internet.herokuapp.com/login') 10 | 11 | username_element = driver.find_element(By.NAME, 'username') 12 | username_element.send_keys('tomsmith') 13 | 14 | password_element = driver.find_element(By.NAME, 'password') 15 | password_element.send_keys('SuperSecretPassword!') 16 | 17 | login_button = driver.find_element(By.TAG_NAME, 'button') 18 | login_button.click() 19 | time.sleep(5) 20 | 21 | subheader_element = driver.find_element(By.CLASS_NAME, 'subheader') 22 | subheader_element.text 23 | driver.close() -------------------------------------------------------------------------------- /selenium/scrap.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import json 4 | 5 | driver = webdriver.Chrome() 6 | driver.get('https://www.sharesansar.com/existing-issues') 7 | 8 | table_element = driver.find_element(By.ID, 'myTableEip') 9 | row_elements = table_element.find_elements(By.TAG_NAME, 'tr') 10 | table_data = [] 11 | 12 | for row in row_elements[1:]: 13 | data_elements = row.find_elements(By.TAG_NAME, 'td') 14 | ipo = { 15 | 'S.N': data_elements[0].text, 16 | 'Symbol': data_elements[1].text, 17 | 'Company': data_elements[2].text, 18 | 'Units': data_elements[3].text 19 | } 20 | table_data.append(ipo) 21 | 22 | with open('ipo_data.json', 'w') as f: 23 | json.dump(table_data,f, indent=2 ) 24 | 25 | driver.close() --------------------------------------------------------------------------------