├── .gitattributes ├── Chapter 1 - PS ├── Problem1.py ├── Problem2.py ├── Problem3.py └── Problem4.py ├── Chapter 1 ├── first.py └── module.py ├── Chapter 10 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py └── 06_problem6.py ├── Chapter 10 ├── 01_class.py ├── 02_instance_vs_class_attr.py ├── 03_self.py └── 04_constructor.py ├── Chapter 11 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py └── 07_problem7.py ├── Chapter 11 ├── 01_inheritance.py ├── 02_multiple_inheritance.py ├── 03_multilevel_inheritance.py ├── 04_super.py ├── 05_class_methods.py ├── 06_property_decorators.py └── 07_operator_overloading.py ├── Chapter 12 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05problem5.py └── tables.txt ├── Chapter 12 ├── 01_walrus.py ├── 02_types.py ├── 03_match_case.py ├── 04_exception.py ├── 05_raising_exceptions.py ├── 06_try_else.py ├── 07_try_finally.py ├── 08_main.py ├── 09_global.py ├── 10_enumerate.py ├── 11_list_comprehensions.py └── module.py ├── Chapter 13 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py ├── 07_problem7.py ├── env1 │ └── .gitkeep ├── env2 │ └── .gitkeep ├── harryenv │ └── .gitkeep └── requirements.txt ├── Chapter 13 ├── 01_venv.py ├── 02_lambda.py ├── 03_join.py ├── 04_format.py ├── 05_map_filter_reduce.py └── requirements.txt ├── Chapter 2 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py └── 06_problem6.py ├── Chapter 2 ├── 01_variables.py ├── 02_datatypes.py ├── 03_rules_variables.py ├── 04_operators.py ├── 05_type.py └── 06_input.py ├── Chapter 3 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py └── 05_problem5.py ├── Chapter 3 ├── 01_intro_to_strings.py ├── 02_negative_slicing.py ├── 03_str_functions.py └── 04_escape_seq.py ├── Chapter 4 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py └── 05_problem5.py ├── Chapter 4 ├── 01_list.py ├── 02_list_methods.py ├── 03_tuple.py └── 04_tuple_methods.py ├── Chapter 5 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py ├── 07_problem7.py ├── 08_problem8.py └── 09_problem9.py ├── Chapter 5 ├── 01_dict.py ├── 02_dict_methods.py ├── 03_sets.py ├── 04_set_methods.py └── 05_set_union_intersection.py ├── Chapter 6 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py └── 07_problem7.py ├── Chapter 6 ├── 01_conditionals.py ├── 02_if_elif_else_ladder.py └── 03_multiple_if_statements.py ├── Chapter 7 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py ├── 07_problem7.py ├── 08_problem8.py ├── 09_problem9.py └── 10_problem10.py ├── Chapter 7 ├── 01_loops.py ├── 02_while_loops.py ├── 03_list_using_while.py ├── 04_for_loops.py ├── 05_for_loop_iterate.py ├── 06_for_with_else.py ├── 07_break_and_continue.py └── 08_pass.py ├── Chapter 8 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem6.py ├── 07_problem7.py └── 08_problem8.py ├── Chapter 8 ├── 01_functions.py ├── 02_quick_quiz.py ├── 03_function_with_arguments.py ├── 04_default_argument.py └── 05_recursion.py ├── Chapter 9 - PS ├── 01_problem1.py ├── 02_problem2.py ├── 03_problem3.py ├── 04_problem4.py ├── 05_problem5.py ├── 06_problem.py ├── 07_problem7.py ├── 08_problem8.py ├── 09_problem9.py ├── 10_problem10.py ├── 11_problem.py ├── file.txt ├── hiscore.txt ├── log.txt ├── old.txt ├── poem.txt ├── renamed_by_python.txt ├── tables │ ├── table_10.txt │ ├── table_11.txt │ ├── table_12.txt │ ├── table_13.txt │ ├── table_14.txt │ ├── table_15.txt │ ├── table_16.txt │ ├── table_17.txt │ ├── table_18.txt │ ├── table_19.txt │ ├── table_2.txt │ ├── table_20.txt │ ├── table_3.txt │ ├── table_4.txt │ ├── table_5.txt │ ├── table_6.txt │ ├── table_7.txt │ ├── table_8.txt │ └── table_9.txt ├── this.txt └── this_copy.txt ├── Chapter 9 ├── 01_file.py ├── 02_file_write.py ├── 03_more_file_functions.py ├── 04_append.py ├── 05_with.py ├── file.txt └── myfile.txt ├── HandWritten_Python_Complete_Notes.pdf ├── Mega Project 1 - Jarvis ├── client.py ├── main.py ├── musicLibrary.py └── temp.mp3 ├── Mega Project 2 - AI AutoReply Bot ├── 01_get_cursor.py ├── 02_openai.py └── 03_bot.py ├── Project 1 ├── main-shortened.py └── main.py ├── Project 2 └── main.py ├── README.md └── The Ultimate Python Handbook.pdf /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Chapter 1 - PS/Problem1.py: -------------------------------------------------------------------------------- 1 | print(''' Twinkle, twinkle, little star, 2 | How I wonder what you are! 3 | Up above the world so high, 4 | Like a diamond in the sky. 5 | 6 | When the blazing sun is gone, 7 | When he nothing shines upon, 8 | Then you show your little light, 9 | Twinkle, twinkle, all the night. 10 | 11 | Then the trav'ller in the dark, 12 | Thanks you for your tiny spark, 13 | He could not see which way to go, 14 | If you did not twinkle so. 15 | 16 | In the dark blue sky you keep, 17 | And often thro' my curtains peep, 18 | For you never shut your eye, 19 | Till the sun is in the sky. 20 | 21 | 'Tis your bright and tiny spark, 22 | Lights the trav'ller in the dark: 23 | Tho' I know not what you are, 24 | Twinkle, twinkle, little star.''') -------------------------------------------------------------------------------- /Chapter 1 - PS/Problem2.py: -------------------------------------------------------------------------------- 1 | # Done using REPL -------------------------------------------------------------------------------- /Chapter 1 - PS/Problem3.py: -------------------------------------------------------------------------------- 1 | import pyttsx3 2 | engine = pyttsx3.init() 3 | engine.say("Hey I am good") 4 | engine.runAndWait() -------------------------------------------------------------------------------- /Chapter 1 - PS/Problem4.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # Select the directory whose content you want to list 4 | directory_path = '/' 5 | 6 | # Use the os module to list the directory content 7 | contents = os.listdir(directory_path) 8 | 9 | # Print the contents of the directory 10 | print(contents) 11 | -------------------------------------------------------------------------------- /Chapter 1/first.py: -------------------------------------------------------------------------------- 1 | print("Hello World") -------------------------------------------------------------------------------- /Chapter 1/module.py: -------------------------------------------------------------------------------- 1 | import pyjokes 2 | 3 | # print("Printing Jokes...") 4 | 5 | # This prints a random joke 6 | joke = pyjokes.get_joke() 7 | print(joke) 8 | 9 | 10 | # so thanks 11 | # that was my program 12 | # another line 13 | # Yet another line -------------------------------------------------------------------------------- /Chapter 10 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | class Programmer: 2 | company = "Microsoft" 3 | def __init__(self, name, salary, pin): 4 | self.name = name 5 | self.salary = salary 6 | self.pin = pin 7 | 8 | 9 | p = Programmer("Harry", 1200000, 245001) 10 | print(p.name, p.salary, p.pin, p.company) 11 | r = Programmer("Rohan", 1200000, 245001) 12 | print(r.name, r.salary, r.pin, r.company) -------------------------------------------------------------------------------- /Chapter 10 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def __init__(self, n): 3 | self.n = n 4 | 5 | def square(self): 6 | print(f"The square is {self.n*self.n}") 7 | 8 | def cube(self): 9 | print(f"The cube is {self.n*self.n*self.n}") 10 | 11 | def squareroot(self): 12 | print(f"The squareroot is {self.n**1/2}") 13 | 14 | a = Calculator(4) 15 | a.square() 16 | a.cube() 17 | a.squareroot() -------------------------------------------------------------------------------- /Chapter 10 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | class Demo: 2 | a = 4 3 | 4 | o = Demo() 5 | print(o.a) # Prints the class attribute because instance attribute is not present 6 | o.a = 0 # Instance attribute is set 7 | print(o.a) # Prints the instance attribute because instance attribute is present 8 | print(Demo.a) # Prints the class attribute -------------------------------------------------------------------------------- /Chapter 10 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def __init__(self, n): 3 | self.n = n 4 | 5 | def square(self): 6 | print(f"The square is {self.n*self.n}") 7 | 8 | def cube(self): 9 | print(f"The cube is {self.n*self.n*self.n}") 10 | 11 | def squareroot(self): 12 | print(f"The squareroot is {self.n**1/2}") 13 | 14 | @staticmethod 15 | def hello(): 16 | print("Hello there!") 17 | 18 | a = Calculator(4) 19 | a.hello() 20 | a.square() 21 | a.cube() 22 | a.squareroot() -------------------------------------------------------------------------------- /Chapter 10 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Train: 4 | 5 | def __init__(self, trainNo): 6 | self.trainNo = trainNo 7 | 8 | def book(self, fro, to): 9 | print(f"Ticket is booked in train no: {self.trainNo} from {fro} to {to}") 10 | 11 | def getStatus(self): 12 | print(f"Train no: {self.trainNo} is running on time") 13 | 14 | def getFare(self, fro, to): 15 | print(f"Ticket fare in train no: {self.trainNo} from {fro} to {to} is {randint(222, 5555)}") 16 | 17 | 18 | t = Train(12399) 19 | t.book("Rampur", "Delhi") 20 | t.getStatus() 21 | t.getFare("Rampur", "Delhi") 22 | -------------------------------------------------------------------------------- /Chapter 10 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Train: 4 | 5 | def __init__(slf, trainNo): 6 | slf.trainNo = trainNo 7 | 8 | def book(harry, fro, to): 9 | print(f"Ticket is booked in train no: {harry.trainNo} from {fro} to {to}") 10 | 11 | def getStatus(self): 12 | print(f"Train no: {self.trainNo} is running on time") 13 | 14 | def getFare(self, fro, to): 15 | print(f"Ticket fare in train no: {self.trainNo} from {fro} to {to} is {randint(222, 5555)}") 16 | 17 | 18 | t = Train(12399) 19 | t.book("Rampur", "Delhi") 20 | t.getStatus() 21 | t.getFare("Rampur", "Delhi") 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter 10/01_class.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | language = "Py" # This is a class attribute 3 | salary = 1200000 4 | 5 | 6 | harry = Employee() 7 | harry.name = "Harry" # This is an instance attribute 8 | print(harry.name, harry.language, harry.salary) 9 | 10 | rohan = Employee() 11 | rohan.name = "Rohan Roro Robinson" 12 | print(rohan.name, rohan.salary, rohan.language) 13 | 14 | # Here name is instance attribute and salary and language are class attributes as they directly belong to the class -------------------------------------------------------------------------------- /Chapter 10/02_instance_vs_class_attr.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | language = "Python" # This is a class attribute 3 | salary = 1200000 4 | 5 | 6 | harry = Employee() 7 | harry.language = "JavaScript" # This is an instance attribute 8 | print(harry.language, harry.salary) 9 | -------------------------------------------------------------------------------- /Chapter 10/03_self.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | language = "Python" # This is a class attribute 3 | salary = 1200000 4 | 5 | def getInfo(self): 6 | print(f"The language is {self.language}. The salary is {self.salary}") 7 | 8 | @staticmethod 9 | def greet(): 10 | print("Good morning") 11 | 12 | 13 | harry = Employee() 14 | # harry.language = "JavaScript" # This is an instance attribute 15 | harry.greet() 16 | harry.getInfo() 17 | # Employee.getInfo(harry) 18 | -------------------------------------------------------------------------------- /Chapter 10/04_constructor.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | language = "Python" # This is a class attribute 3 | salary = 1200000 4 | 5 | def __init__(self, name, salary, language): # dunder method which is automatically called 6 | self.name = name 7 | self.salary = salary 8 | self.language = language 9 | print("I am creating an object") 10 | 11 | 12 | def getInfo(self): 13 | print(f"The language is {self.language}. The salary is {self.salary}") 14 | 15 | @staticmethod 16 | def greet(): 17 | print("Good morning") 18 | 19 | 20 | harry = Employee("Harry", 1300000, "JavaScript") 21 | # harry.name = "Harry" 22 | print(harry.name, harry.salary, harry.language) 23 | 24 | rohan = Employee() -------------------------------------------------------------------------------- /Chapter 11 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | class TwoDVector: 2 | def __init__(self, i, j): 3 | self.i = i 4 | self.j = j 5 | 6 | def show(self): 7 | print(f"The vector is {self.i}i + {self.j}j ") 8 | 9 | 10 | class ThreeDVector(TwoDVector): 11 | def __init__(self, i, j, k): 12 | super().__init__(i, j) 13 | self.k = k 14 | 15 | def show(self): 16 | print(f"The vector is {self.i}i + {self.j}j + {self.k}k") 17 | 18 | a = TwoDVector(1, 2) 19 | a.show() 20 | b = ThreeDVector(5, 2, 3) 21 | b.show() -------------------------------------------------------------------------------- /Chapter 11 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | class Animals: 2 | pass 3 | 4 | class Pets(Animals): 5 | pass 6 | 7 | class Dog(Pets): 8 | 9 | @staticmethod 10 | def bark(): 11 | print("Bow Bow!") 12 | 13 | 14 | d = Dog() 15 | 16 | d.bark() -------------------------------------------------------------------------------- /Chapter 11 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | salary = 234 3 | increment = 20 4 | 5 | @property 6 | def salaryAfterIncrement(self): 7 | return (self.salary + self.salary * (self.increment/100)) 8 | 9 | @salaryAfterIncrement.setter 10 | def salaryAfterIncrement(self, salary): 11 | self.increment = ((salary/self.salary) -1)*100 12 | 13 | 14 | 15 | 16 | e = Employee() 17 | # print(e.salaryAfterIncrement) 18 | e.salaryAfterIncrement = 280.8 19 | print(e.increment) -------------------------------------------------------------------------------- /Chapter 11 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | class Complex: 2 | def __init__(self, r, i): 3 | self.r = r 4 | self.i = i 5 | 6 | def __add__(self, c2): 7 | return Complex(self.r + c2.r, self.i + c2.i) 8 | 9 | def __mul__(self, c2): 10 | real_part = self.r * c2.r - self.i * c2.i 11 | imag_part = self.r * c2.i + self.i * c2.r 12 | return Complex(real_part, imag_part) 13 | 14 | def __str__(self): 15 | return f"{self.r} + {self.i}i" 16 | 17 | 18 | 19 | c1 = Complex(1, 2) 20 | c2 = Complex(3, 4) 21 | print(c1 + c2) 22 | print(c1*c2) -------------------------------------------------------------------------------- /Chapter 11 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, x, y, z): 3 | self.x = x 4 | self.y = y 5 | self.z = z 6 | 7 | def __add__(self, other): 8 | result = Vector(self.x + other.x, self.y + other.y, self.z + other.z) 9 | return result 10 | 11 | def __mul__(self, other): 12 | result = self.x * other.x + self.y * other.y + self.z * other.z 13 | return result 14 | 15 | def __str__(self): 16 | return f"Vector({self.x}, {self.y}, {self.z})" 17 | 18 | # Test the implementation 19 | v1 = Vector(1, 2, 3) 20 | v2 = Vector(4, 5, 6) 21 | v3 = Vector(7, 8, 9) # Same dimension vector 22 | 23 | print(v1 + v2) # Output: Vector(5, 7, 9) 24 | print(v1 * v2) # Output: 32 25 | 26 | print(v1 + v3) # Output: Vector(8, 10, 12) 27 | print(v1 * v3) # Output: 50 28 | -------------------------------------------------------------------------------- /Chapter 11 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, x, y, z): 3 | self.x = x 4 | self.y = y 5 | self.z = z 6 | 7 | def __add__(self, other): 8 | result = Vector(self.x + other.x, self.y + other.y, self.z + other.z) 9 | return result 10 | 11 | def __mul__(self, other): 12 | result = self.x * other.x + self.y * other.y + self.z * other.z 13 | return result 14 | 15 | def __str__(self): 16 | return f"{self.x}i + {self.y}j + {self.z}k" 17 | 18 | # Test the implementation 19 | v1 = Vector(1, 2, 3) 20 | v2 = Vector(4, 5, 6) 21 | v3 = Vector(7, 8, 9) # Same dimension vector 22 | 23 | print(v1 + v2) # Output: Vector(5, 7, 9) 24 | print(v1 * v2) # Output: 32 25 | 26 | print(v1 + v3) # Output: Vector(8, 10, 12) 27 | print(v1 * v3) # Output: 50 28 | -------------------------------------------------------------------------------- /Chapter 11 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, l): 3 | self.l = l 4 | 5 | 6 | 7 | def __len__(self): 8 | return len(self.l) 9 | 10 | # Test the implementation 11 | v1 = Vector([1, 2, 3]) 12 | print(len(v1)) -------------------------------------------------------------------------------- /Chapter 11/01_inheritance.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "ITC" 3 | def show(self): 4 | print(f"The name of the Employee is {self.name} and the salary is {self.salary}") 5 | 6 | 7 | # class Programmer: 8 | # company = "ITC Infotech" 9 | # def show(self): 10 | # print(f"The name is {self.name} and the salary is {self.salary}") 11 | 12 | # def showLanguage(self): 13 | # print(f"The name is {self.name} and he is good with {self.language} language") 14 | 15 | 16 | class Programmer(Employee): 17 | company = "ITC Infotech" 18 | def showLanguage(self): 19 | print(f"The name is {self.name} and he is good with {self.language} language") 20 | 21 | 22 | a = Employee() 23 | b = Programmer() 24 | 25 | print(a.company, b.company) -------------------------------------------------------------------------------- /Chapter 11/02_multiple_inheritance.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "ITC" 3 | name = "Default name" 4 | def show(self): 5 | print(f"The name of the Employee is {self.name} and the company is {self.company}") 6 | 7 | class Coder: 8 | language = "Python" 9 | def printLanguages(self): 10 | print(f"Out of all the languages here is your language: {self.language}") 11 | 12 | 13 | 14 | class Programmer(Employee, Coder): 15 | company = "ITC Infotech" 16 | def showLanguage(self): 17 | print(f"The name is {self.company} and he is good with {self.language} language") 18 | 19 | 20 | a = Employee() 21 | b = Programmer() 22 | 23 | b.show() 24 | b.printLanguages() 25 | b.showLanguage() -------------------------------------------------------------------------------- /Chapter 11/03_multilevel_inheritance.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | a = 1 3 | 4 | class Programmer(Employee): 5 | b = 2 6 | 7 | class Manager(Programmer): 8 | c = 3 9 | 10 | o = Employee() 11 | print(o.a) # Prints the a attribute 12 | # print(o.b) # Shows an error as there is no b attribute in Employee class 13 | 14 | o = Programmer() 15 | print(o.a, o.b) 16 | 17 | 18 | o = Manager() 19 | print(o.a, o.b, o.c) 20 | -------------------------------------------------------------------------------- /Chapter 11/04_super.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self): 3 | print("Constructor of Employee") 4 | a = 1 5 | 6 | class Programmer(Employee): 7 | def __init__(self): 8 | print("Constructor of Programmer") 9 | b = 2 10 | 11 | class Manager(Programmer): 12 | def __init__(self): 13 | super().__init__() 14 | print("Constructor of Manager") 15 | c = 3 16 | 17 | # o = Employee() 18 | # print(o.a) # Prints the a attribute 19 | 20 | # o = Programmer() 21 | # print(o.a, o.b) 22 | 23 | 24 | o = Manager() 25 | print(o.a, o.b, o.c) 26 | -------------------------------------------------------------------------------- /Chapter 11/05_class_methods.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | a = 1 3 | 4 | @classmethod 5 | def show(cls): 6 | print(f"The class attribute of a is {cls.a}") 7 | 8 | e = Employee() 9 | e.a = 45 10 | 11 | e.show() -------------------------------------------------------------------------------- /Chapter 11/06_property_decorators.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | a = 1 3 | 4 | @classmethod 5 | def show(cls): 6 | print(f"The class attribute of a is {cls.a}") 7 | 8 | @property 9 | def name(self): 10 | return f"{self.fname} {self.lname}" 11 | 12 | @name.setter 13 | def name (self,value): 14 | self.fname = value.split(" ")[0] 15 | self.lname = value.split(" ")[1] 16 | 17 | e = Employee() 18 | e.a = 45 19 | 20 | e.name = "Harry Khan" 21 | print(e.fname, e.lname) 22 | 23 | e.show() -------------------------------------------------------------------------------- /Chapter 11/07_operator_overloading.py: -------------------------------------------------------------------------------- 1 | class Number: 2 | def __init__(self, n): 3 | self.n = n 4 | 5 | def __add__(self, num): 6 | return self.n + num.n 7 | 8 | n = Number(1) 9 | m = Number(2) 10 | 11 | print(n + m) 12 | 13 | -------------------------------------------------------------------------------- /Chapter 12 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | with open("1.txt", "r") as f: 4 | print(f.read()) 5 | except Exception as e: 6 | print(e) 7 | 8 | try: 9 | with open("2.txt", "r") as f: 10 | print(f.read()) 11 | except Exception as e: 12 | print(e) 13 | 14 | try: 15 | with open("3.txt", "r") as f: 16 | print(f.read()) 17 | except Exception as e: 18 | print(e) 19 | 20 | 21 | print("Thank You!") -------------------------------------------------------------------------------- /Chapter 12 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | l = [1, 2, 3, 4, 5, 6 ,7 , 8] 2 | 3 | for i, item in enumerate(l): 4 | if i == 2 or i == 4 or i == 6: 5 | print(item) 6 | -------------------------------------------------------------------------------- /Chapter 12 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter a number: ")) 2 | 3 | table = [n*i for i in range(1, 11)] 4 | print(table) -------------------------------------------------------------------------------- /Chapter 12 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | try: 2 | a = int(input("Enter a: ")) 3 | b = int(input("Enter b: ")) 4 | print(a/b) 5 | except ZeroDivisionError as v: 6 | print("Infinite") 7 | -------------------------------------------------------------------------------- /Chapter 12 - PS/05problem5.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter a number: ")) 2 | 3 | table = [n*i for i in range(1, 11)] 4 | with open("tables.txt", "a") as f: 5 | f.write(f"Table of {n}: {str(table)} \n") -------------------------------------------------------------------------------- /Chapter 12 - PS/tables.txt: -------------------------------------------------------------------------------- 1 | Table of 5: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] 2 | Table of 2: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] 3 | Table of 22: [22, 44, 66, 88, 110, 132, 154, 176, 198, 220] 4 | Table of 3323423: [3323423, 6646846, 9970269, 13293692, 16617115, 19940538, 23263961, 26587384, 29910807, 33234230] 5 | -------------------------------------------------------------------------------- /Chapter 12/01_walrus.py: -------------------------------------------------------------------------------- 1 | # Using walrus operator 2 | if (n := len([1, 2, 3, 4, 5])) > 3: 3 | print(f"List is too long ({n} elements, expected <= 3)") # Output: List is too long (5 elements, expected <= 3) -------------------------------------------------------------------------------- /Chapter 12/02_types.py: -------------------------------------------------------------------------------- 1 | from typing import List, Union, Tuple 2 | 3 | n : int = 5 4 | 5 | name: str = "Harry" 6 | 7 | 8 | def sum(a: int, b: int) -> int: 9 | return a+b 10 | 11 | -------------------------------------------------------------------------------- /Chapter 12/03_match_case.py: -------------------------------------------------------------------------------- 1 | def http_status(status): 2 | match status: 3 | case 200: 4 | return "OK" 5 | case 404: 6 | return "Not Found" 7 | case 500: 8 | return "Internal Server Error" 9 | case _: 10 | return "Unknown status" 11 | 12 | 13 | print(http_status(5007)) -------------------------------------------------------------------------------- /Chapter 12/04_exception.py: -------------------------------------------------------------------------------- 1 | try: 2 | a = int(input("Hey, Enter a number: ")) 3 | print(a) 4 | 5 | except ValueError as v: 6 | print("Heyyyy") 7 | print(v) 8 | 9 | except Exception as e: 10 | print(e) 11 | 12 | print("Thank You") -------------------------------------------------------------------------------- /Chapter 12/05_raising_exceptions.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter a number: ")) 2 | b = int(input("Enter second number: ")) 3 | 4 | if(b == 0): 5 | raise ZeroDivisionError("Hey our program is not meant to divide numbers by zero") 6 | else: 7 | print(f"The division a/b is {a/b}") -------------------------------------------------------------------------------- /Chapter 12/06_try_else.py: -------------------------------------------------------------------------------- 1 | try: 2 | a = int(input("Hey, Enter a number: ")) 3 | print(a) 4 | 5 | 6 | except Exception as e: 7 | print(e) 8 | 9 | 10 | else: 11 | print("I am inside else") 12 | 13 | -------------------------------------------------------------------------------- /Chapter 12/07_try_finally.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | try: 3 | a = int(input("Hey, Enter a number: ")) 4 | print(a) 5 | return 6 | 7 | 8 | except Exception as e: 9 | print(e) 10 | return 11 | 12 | 13 | finally: 14 | print("Hey I am inside of finally") 15 | 16 | 17 | main() -------------------------------------------------------------------------------- /Chapter 12/08_main.py: -------------------------------------------------------------------------------- 1 | from module import myFunc 2 | 3 | -------------------------------------------------------------------------------- /Chapter 12/09_global.py: -------------------------------------------------------------------------------- 1 | a = 89 2 | 3 | def fun(): 4 | # global a 5 | a = 3 6 | print(a) 7 | 8 | 9 | fun() 10 | print(a) -------------------------------------------------------------------------------- /Chapter 12/10_enumerate.py: -------------------------------------------------------------------------------- 1 | l = [3, 513, 53, 535] 2 | 3 | # index = 0 4 | # for item in l: 5 | # print(f"The item number at index {index} is {item}") 6 | # index += 1 7 | 8 | # This can be simplified using enumerate function 9 | 10 | for index, item in enumerate(l): 11 | print(f"The item number at index {index} is {item}") 12 | -------------------------------------------------------------------------------- /Chapter 12/11_list_comprehensions.py: -------------------------------------------------------------------------------- 1 | myList = [1, 2, 9, 5, 3, 5] 2 | 3 | # squaredList = [] 4 | # for item in myList: 5 | # squaredList.append(item*item) 6 | 7 | squaredList = [i*i for i in myList] 8 | 9 | print(squaredList) -------------------------------------------------------------------------------- /Chapter 12/module.py: -------------------------------------------------------------------------------- 1 | def myFunc(): 2 | print("Hello world!") 3 | 4 | 5 | 6 | if __name__ == "__main__": 7 | # If this code is directly executed by running the file its present in 8 | print("We are directly running this code") 9 | myFunc() 10 | print(__name__) -------------------------------------------------------------------------------- /Chapter 13 - PS/01_problem1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13 - PS/01_problem1.py -------------------------------------------------------------------------------- /Chapter 13 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | name = input("Enter name: ") 2 | marks = int(input("Enter marks: ")) 3 | phone = int(input("Phone number: ")) 4 | 5 | s = "The name of the student is {}, his marks are {} and phone number is {}".format(name, marks, phone) 6 | 7 | print(s) -------------------------------------------------------------------------------- /Chapter 13 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | table = [str(7*i) for i in range(1, 11)] 2 | 3 | s = "\n".join(table) 4 | print(s) -------------------------------------------------------------------------------- /Chapter 13 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | def divisible5(n): 2 | if(n%5 == 0): 3 | return True 4 | return False 5 | 6 | a = [1,2,34234,53,6234235,64343, 65,754,45,55] 7 | 8 | f = list(filter(divisible5, a)) 9 | print(f) -------------------------------------------------------------------------------- /Chapter 13 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | l = [111, 2, 65, 5553, 635, 65, 74, 45,55] 3 | 4 | 5 | def greater(a, b): 6 | if (a>b): 7 | return a 8 | return b 9 | 10 | print(reduce(greater, l)) -------------------------------------------------------------------------------- /Chapter 13 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | # pip freeze > requirements.txt 2 | # virtualenv harryenv -------------------------------------------------------------------------------- /Chapter 13 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route("/") 6 | def hello_world(): 7 | return "

Hello, World!

" 8 | 9 | app.run() -------------------------------------------------------------------------------- /Chapter 13 - PS/env1/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13 - PS/env1/.gitkeep -------------------------------------------------------------------------------- /Chapter 13 - PS/env2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13 - PS/env2/.gitkeep -------------------------------------------------------------------------------- /Chapter 13 - PS/harryenv/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13 - PS/harryenv/.gitkeep -------------------------------------------------------------------------------- /Chapter 13 - PS/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13 - PS/requirements.txt -------------------------------------------------------------------------------- /Chapter 13/01_venv.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13/01_venv.py -------------------------------------------------------------------------------- /Chapter 13/02_lambda.py: -------------------------------------------------------------------------------- 1 | # def square(n): 2 | # return n*n 3 | 4 | square = lambda x: x*x 5 | 6 | print(square(5)) -------------------------------------------------------------------------------- /Chapter 13/03_join.py: -------------------------------------------------------------------------------- 1 | a = ["Harry", "Rohan", "Shubham"] 2 | 3 | final = "::".join(a) 4 | print(final) -------------------------------------------------------------------------------- /Chapter 13/04_format.py: -------------------------------------------------------------------------------- 1 | a = "{1} is a good {0}".format("harry", "boy") 2 | 3 | print(a) -------------------------------------------------------------------------------- /Chapter 13/05_map_filter_reduce.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | # Map Example 3 | l = [1, 2, 3, 4, 5] 4 | 5 | square = lambda x: x*x 6 | 7 | sqList = map(square, l) 8 | print(list(sqList)) 9 | 10 | # Filter Example 11 | def even(n): 12 | if (n%2 == 0): 13 | return True 14 | return False 15 | 16 | onlyEven= filter(even, l) 17 | print(list(onlyEven)) 18 | 19 | # Reduce Example 20 | def sum(a, b): 21 | return a + b 22 | 23 | mul = lambda x,y:x*y 24 | 25 | print(reduce(sum, l)) 26 | print(reduce(mul, l)) -------------------------------------------------------------------------------- /Chapter 13/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 13/requirements.txt -------------------------------------------------------------------------------- /Chapter 2 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | a = 1 2 | 3 | b = 5 4 | 5 | print(a + b) -------------------------------------------------------------------------------- /Chapter 2 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | a = 37 2 | 3 | b = 5 4 | 5 | print("Remainder when a is divided by b is", a % b) -------------------------------------------------------------------------------- /Chapter 2 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | a = input("Enter the value of a: ") 2 | print(type(a)) -------------------------------------------------------------------------------- /Chapter 2 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter number 1: ")) 2 | b = int(input("Enter number 2: ")) 3 | 4 | print("a is greater than b is", a>b) -------------------------------------------------------------------------------- /Chapter 2 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter number 1: ")) 2 | b = int(input("Enter number 2: ")) 3 | 4 | 5 | print("The average of these two number is", (a+b)/2) -------------------------------------------------------------------------------- /Chapter 2 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter your number: ")) 2 | 3 | 4 | print("The square of the number is", a**2) 5 | print("The square of the number is", a*a) 6 | # print("The square of the number is", a^2) # Incorrect for finding square of a number in Python -------------------------------------------------------------------------------- /Chapter 2/01_variables.py: -------------------------------------------------------------------------------- 1 | a = 1 2 | 3 | b = 2 4 | 5 | c = 7 6 | 7 | name = "harry" 8 | 9 | print(a + b) -------------------------------------------------------------------------------- /Chapter 2/02_datatypes.py: -------------------------------------------------------------------------------- 1 | a = 1 # a is an integer 2 | 3 | b = 5.22 # b is a floating point number 4 | 5 | c = "Harry" # c is a string 6 | 7 | d = False # d is a boolean variable 8 | 9 | e = None # e is a none type variable -------------------------------------------------------------------------------- /Chapter 2/03_rules_variables.py: -------------------------------------------------------------------------------- 1 | a = 23 2 | 3 | aaa = 435 4 | 5 | harry = 34 6 | 7 | sameer = 45 8 | 9 | _samerr = 34 10 | 11 | # @sameer = 56 # Invalid due to @ symbol 12 | # s@meer # Invalid due to @ symbol -------------------------------------------------------------------------------- /Chapter 2/04_operators.py: -------------------------------------------------------------------------------- 1 | # Arithmetic Operators 2 | a = 7 3 | b = 4 4 | c = a + b 5 | print(c) 6 | 7 | # Assignment Operators 8 | a = 4-2 # Assign 4-2 in a 9 | print(a) 10 | b = 6 11 | # b += 3 # Increment the value of b by 3 and then assign it to b 12 | b -= 3 # Decrement the value of b by 3 and then assign it to b 13 | print(b) 14 | 15 | # Comparison Operators 16 | 17 | d = 5==5 18 | 19 | print(d) 20 | 21 | 22 | # Logical Operators 23 | 24 | e = True or False 25 | 26 | # Truth table of 'or' 27 | print("True or False is ", True or False) 28 | print("True or True is ", True or True) 29 | print("False or True is ", False or True) 30 | print("False or False is ", False or False) 31 | 32 | # Truth table of 'and' 33 | print("True and False is ", True and False) 34 | print("True and True is ", True and True) 35 | print("False and True is ", False and True) 36 | print("False and False is ", False and False) 37 | 38 | print(not(True)) -------------------------------------------------------------------------------- /Chapter 2/05_type.py: -------------------------------------------------------------------------------- 1 | a = "31.2" 2 | b = float(a) # a but the type should be float 3 | t = type(b) 4 | 5 | print(t) -------------------------------------------------------------------------------- /Chapter 2/06_input.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter number 1: ")) 2 | 3 | b = int(input("Enter number 2: ")) 4 | 5 | print("Number a is: ", a) 6 | print("Number b is: ", b) 7 | print("Sum is ", a + b) 8 | -------------------------------------------------------------------------------- /Chapter 3 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | name = input("Enter your name: ") 2 | 3 | print(f"Good Afternoon, {name} ") -------------------------------------------------------------------------------- /Chapter 3 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | letter = '''Dear <|Name|>, 2 | You are selected! 3 | <|Date|> ''' 4 | 5 | print(letter.replace("<|Name|>", "Harry").replace("<|Date|", "24 September 2050")) -------------------------------------------------------------------------------- /Chapter 3 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | name = "Harry is a good boy and " 2 | 3 | print(name.find(" ")) -------------------------------------------------------------------------------- /Chapter 3 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | name = "Harry is a good boy and " 2 | 3 | print(name.replace(" ", " ")) 4 | print(name) # Strings are immutable which means that you cannot change them by running functions on them -------------------------------------------------------------------------------- /Chapter 3 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | letter = "Dear Harry,\n\tThis python course is nice.\nThanks!" 2 | 3 | print(letter) -------------------------------------------------------------------------------- /Chapter 3/01_intro_to_strings.py: -------------------------------------------------------------------------------- 1 | name = "Harry" 2 | 3 | nameshort = name[0:3] # start from index 0 all the way till 3 (excluding 3) 4 | print(nameshort) 5 | character1 = name[1] 6 | print(character1) -------------------------------------------------------------------------------- /Chapter 3/02_negative_slicing.py: -------------------------------------------------------------------------------- 1 | name = "Harry" 2 | 3 | print(name[0:3]) 4 | 5 | print(name[-4: -1]) 6 | print(name[1:4]) 7 | 8 | print(name[:4]) # is same as print(name[0:4]) 9 | print(name[1:]) # is same as print(name[1:5]) 10 | print(name[1:5]) -------------------------------------------------------------------------------- /Chapter 3/03_str_functions.py: -------------------------------------------------------------------------------- 1 | name = "harry" 2 | 3 | print(len(name)) 4 | print(name.endswith("rry")) 5 | print(name.startswith("ha")) 6 | print(name.capitalize()) -------------------------------------------------------------------------------- /Chapter 3/04_escape_seq.py: -------------------------------------------------------------------------------- 1 | a = 'Harry is a good boy\nbut not a bad \'boy\'' 2 | 3 | 4 | print(a) -------------------------------------------------------------------------------- /Chapter 4 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | fruits = [] 2 | 3 | f1 = input("Enter Fruit name: ") 4 | fruits.append(f1) 5 | f2 = input("Enter Fruit name: ") 6 | fruits.append(f2) 7 | f3 = input("Enter Fruit name: ") 8 | fruits.append(f3) 9 | f4 = input("Enter Fruit name: ") 10 | fruits.append(f4) 11 | f5 = input("Enter Fruit name: ") 12 | fruits.append(f5) 13 | f6 = input("Enter Fruit name: ") 14 | fruits.append(f6) 15 | f7 = input("Enter Fruit name: ") 16 | fruits.append(f7) 17 | 18 | print(fruits) -------------------------------------------------------------------------------- /Chapter 4 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | marks = [] 2 | 3 | f1 = int(input("Enter Marks here: ")) 4 | marks.append(f1) 5 | f2 = int(input("Enter Marks here: ")) 6 | marks.append(f2) 7 | f3 = int(input("Enter Marks here: ")) 8 | marks.append(f3) 9 | f4 = int(input("Enter Marks here: ")) 10 | marks.append(f4) 11 | f5 = int(input("Enter Marks here: ")) 12 | marks.append(f5) 13 | f6 = int(input("Enter Marks here: ")) 14 | marks.append(f6) 15 | 16 | marks.sort() 17 | 18 | print(marks) -------------------------------------------------------------------------------- /Chapter 4 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | a = (34, 234, "Harry") 2 | 3 | a[2] = "Larry" -------------------------------------------------------------------------------- /Chapter 4 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | l = [3, 3, 5, 1] 2 | 3 | 4 | print(sum(l)) -------------------------------------------------------------------------------- /Chapter 4 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | a = (7, 0, 8, 0, 0, 9) 2 | 3 | n = a.count(0) 4 | print(n) -------------------------------------------------------------------------------- /Chapter 4/01_list.py: -------------------------------------------------------------------------------- 1 | friends = ["Apple", "Orange", 5, 345.06, False, "Aakash", "Rohan"] 2 | 3 | print(friends[0]) 4 | friends[0] = "Grapes" # Unlike Strings lists are mutable 5 | 6 | print(friends[0]) 7 | print(friends[1:4]) -------------------------------------------------------------------------------- /Chapter 4/02_list_methods.py: -------------------------------------------------------------------------------- 1 | friends = ["Apple", "Orange", 5, 345.06, False, "Aakash", "Rohan"] 2 | print(friends) 3 | friends.append("Harry") 4 | print(friends) 5 | 6 | l1 = [1, 34,62, 2, 6, 11] 7 | # l1.sort() 8 | # l1.reverse() 9 | # l1.insert(2, 333333) # Insert 333333 such that its index in the list is 3 10 | value = l1.pop(3) 11 | print(value) 12 | print(l1) -------------------------------------------------------------------------------- /Chapter 4/03_tuple.py: -------------------------------------------------------------------------------- 1 | a = (1,45,342,3424,False, "Rohan", "Shivam") 2 | print(a) 3 | print(type(a)) -------------------------------------------------------------------------------- /Chapter 4/04_tuple_methods.py: -------------------------------------------------------------------------------- 1 | a = (1,45,342,3424,False, 45, "Rohan", "Shivam") 2 | print(a) 3 | 4 | no = a.count(45) 5 | print(no) 6 | 7 | i = a.index(3424) 8 | print(i) 9 | 10 | print(len(a)) -------------------------------------------------------------------------------- /Chapter 5 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | words = { 2 | "madad": "Help", 3 | "kursi": "Chair", 4 | "billi": "Cat" 5 | } 6 | 7 | word = input("Enter the word you want meaning of: ") 8 | 9 | print(words[word]) -------------------------------------------------------------------------------- /Chapter 5 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | s = set() 2 | n = input("Enter number: ") 3 | s.add(int(n)) 4 | n = input("Enter number: ") 5 | s.add(int(n)) 6 | n = input("Enter number: ") 7 | s.add(int(n)) 8 | n = input("Enter number: ") 9 | s.add(int(n)) 10 | n = input("Enter number: ") 11 | s.add(int(n)) 12 | n = input("Enter number: ") 13 | s.add(int(n)) 14 | n = input("Enter number: ") 15 | s.add(int(n)) 16 | n = input("Enter number: ") 17 | s.add(int(n)) 18 | 19 | print(s) -------------------------------------------------------------------------------- /Chapter 5 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | s = set() 2 | s.add(18) 3 | s.add("18") 4 | 5 | print(s) -------------------------------------------------------------------------------- /Chapter 5 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | s = set() 2 | s.add(20) 3 | s.add(20.0) 4 | s.add('20') # length of s after these operations? 5 | 6 | print(len(s)) -------------------------------------------------------------------------------- /Chapter 5 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | s = {} 2 | print(type(s)) -------------------------------------------------------------------------------- /Chapter 5 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | d = {} 2 | 3 | name = input("Enter friends name: ") 4 | lang = input("Enter Language name: ") 5 | d.update({name: lang}) 6 | 7 | name = input("Enter friends name: ") 8 | lang = input("Enter Language name: ") 9 | d.update({name: lang}) 10 | 11 | name = input("Enter friends name: ") 12 | lang = input("Enter Language name: ") 13 | d.update({name: lang}) 14 | 15 | name = input("Enter friends name: ") 16 | lang = input("Enter Language name: ") 17 | d.update({name: lang}) 18 | 19 | 20 | print(d) -------------------------------------------------------------------------------- /Chapter 5 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | # The values entered later will be updated -------------------------------------------------------------------------------- /Chapter 5 - PS/08_problem8.py: -------------------------------------------------------------------------------- 1 | # Nothing will happen. The values can be same 2 | -------------------------------------------------------------------------------- /Chapter 5 - PS/09_problem9.py: -------------------------------------------------------------------------------- 1 | s = {8, 7, 12, "Harry", [1,2]} 2 | 3 | s[4][0] = 9 -------------------------------------------------------------------------------- /Chapter 5/01_dict.py: -------------------------------------------------------------------------------- 1 | d = {} # Empty dictionary 2 | marks = { 3 | "Harry": 100, 4 | "Shubham": 56, 5 | "Rohan": 23 6 | } 7 | 8 | 9 | # print(marks, type(marks)) 10 | print(marks["Harry"]) -------------------------------------------------------------------------------- /Chapter 5/02_dict_methods.py: -------------------------------------------------------------------------------- 1 | marks = { 2 | "Harry": 100, 3 | "Shubham": 56, 4 | "Rohan": 23, 5 | 0: "Harry" 6 | } 7 | 8 | # print(marks.items()) 9 | # print(marks.keys()) 10 | # print(marks.values()) 11 | # marks.update({"Harry": 99, "Renuka": 100}) 12 | # print(marks) 13 | 14 | print(marks.get("Harry2")) # Prints None 15 | print(marks["Harry2"]) # Returns an error -------------------------------------------------------------------------------- /Chapter 5/03_sets.py: -------------------------------------------------------------------------------- 1 | e = set() # Dont use s = {} as it will create an empty dictionary 2 | s = {1, 5, 32, 54,5, 5, 5} 3 | 4 | 5 | print(s) -------------------------------------------------------------------------------- /Chapter 5/04_set_methods.py: -------------------------------------------------------------------------------- 1 | s = {1, 5, 32, 54,5, 5, 5, "Harry"} 2 | 3 | print(s, type(s)) 4 | 5 | s.add(566) 6 | print(s, type(s)) 7 | s.remove(1) 8 | print(s, type(s)) -------------------------------------------------------------------------------- /Chapter 5/05_set_union_intersection.py: -------------------------------------------------------------------------------- 1 | s1 = {1, 45, 6, 78} 2 | s2 = {7, 8, 1, 78} 3 | 4 | print(s1.union(s2)) 5 | print(s1.intersection(s2)) -------------------------------------------------------------------------------- /Chapter 6 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | a1 = int(input("Enter number 1: ")) 2 | a2 = int(input("Enter number 2: ")) 3 | a3 = int(input("Enter number 3: ")) 4 | a4 = int(input("Enter number 4: ")) 5 | 6 | if(a1>a2 and a1>a3 and a1>a4): 7 | print("Greatest number is a1:", a1) 8 | 9 | elif(a2>a1 and a2>a3 and a2>a4): 10 | print("Greatest number is a2:", a2) 11 | 12 | elif(a3>a1 and a3>a2 and a3>a4): 13 | print("Greatest number is a3:", a3) 14 | 15 | elif(a4>a1 and a4>a2 and a4>a3): 16 | print("Greatest number is a4:", a4) -------------------------------------------------------------------------------- /Chapter 6 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | marks1 = int(input("Enter Marks 1: ")) 2 | marks2 = int(input("Enter Marks 2: ")) 3 | marks3 = int(input("Enter Marks 3: ")) 4 | 5 | # Check for total percentage 6 | total_percentage = (100*(marks1 + marks2 + marks3))/300 7 | 8 | if(total_percentage>=40 and marks1>=33 and marks2>=33 and marks3>=33): 9 | print("You are passed:", total_percentage) 10 | 11 | else: 12 | print("You failed, try again next year:", total_percentage) 13 | -------------------------------------------------------------------------------- /Chapter 6 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | p1 = "Make a lot of money" 2 | p2 = "buy now" 3 | p3 = "subscribe this" 4 | p4 = "click this" 5 | 6 | message = input("Enter your comment: ") 7 | 8 | if((p1 in message) or (p2 in message )or (p3 in message) or (p4 in message)): 9 | print("This comment is a spam") 10 | 11 | else: 12 | print("This comment is not a spam") -------------------------------------------------------------------------------- /Chapter 6 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | username = input("Enter username: ") 2 | 3 | if(len(username)<10): 4 | print("Your username contains less than 10 characters") 5 | else: 6 | print("Your username contains more than or equal to 10 characters") -------------------------------------------------------------------------------- /Chapter 6 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | l = ["Harry", "Rohan", "Shubham", "Divya"] 2 | 3 | name = input("Enter your name: ") 4 | 5 | if(name in l): 6 | print("Your name is in the list") 7 | else: 8 | print("Your name is not in the list") -------------------------------------------------------------------------------- /Chapter 6 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | marks = int(input("Enter your marks: ")) 2 | 3 | if(marks<=100 and marks>=90): 4 | grade = "Ex" 5 | elif(marks<90 and marks>=80): 6 | grade = "A" 7 | elif(marks<80 and marks>=70): 8 | grade = "B" 9 | elif(marks<70 and marks>=60): 10 | grade = "C" 11 | elif(marks<60 and marks>=50): 12 | grade = "D" 13 | elif(marks<50): 14 | grade = "F" 15 | 16 | print("Your grade is:", grade) -------------------------------------------------------------------------------- /Chapter 6 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | post = input("Enter the post: ") 2 | 3 | 4 | 5 | if("harry" in post.lower()): 6 | print("This post is talking about harry") 7 | 8 | else: 9 | print("This post is not talking about harry") -------------------------------------------------------------------------------- /Chapter 6/01_conditionals.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter your age: ")) 2 | 3 | # If else statement 4 | if(a>=18): 5 | print("You are above the age of consent") 6 | print("Good for you") 7 | 8 | else: 9 | print("You are below the age of consent") 10 | 11 | 12 | print("End of Program") 13 | 14 | -------------------------------------------------------------------------------- /Chapter 6/02_if_elif_else_ladder.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter your age: ")) 2 | 3 | # If elif else ladder 4 | if(a>=18): 5 | print("You are above the age of consent") 6 | print("Good for you") 7 | 8 | elif(a<0): 9 | print("You are entering an invalid negative age") 10 | 11 | elif(a==0): 12 | print("You are entering 0 which is not a valid age") 13 | 14 | else: 15 | print("You are below the age of consent") 16 | 17 | 18 | print("End of Program") 19 | 20 | -------------------------------------------------------------------------------- /Chapter 6/03_multiple_if_statements.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter your age: ")) 2 | 3 | # If statement no: 1 4 | if(a%2 == 0): 5 | print("a is even") 6 | # End of If statement no: 1 7 | 8 | # If statement no: 2 9 | if(a>=18): 10 | print("You are above the age of consent") 11 | print("Good for you") 12 | 13 | elif(a<0): 14 | print("You are entering an invalid negative age") 15 | 16 | else: 17 | print("You are below the age of consent") 18 | # End of If statement no: 2 19 | 20 | print("End of Program") 21 | 22 | -------------------------------------------------------------------------------- /Chapter 7 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter a number: ")) 2 | 3 | for i in range(1, 11): 4 | print(f"{n} X {i} = {n * i}") -------------------------------------------------------------------------------- /Chapter 7 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | l = ["Harry", "Soham", "Sachin", "Rahul"] 2 | 3 | for name in l: 4 | if(name.startswith("S")): 5 | print(f"Hello {name}") -------------------------------------------------------------------------------- /Chapter 7 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter a number: ")) 2 | 3 | i = 1 4 | 5 | while(i<11): 6 | print(f"{n} X {i} = {n * i}") 7 | i += 1 -------------------------------------------------------------------------------- /Chapter 7 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter a number: ")) 2 | 3 | for i in range(2, n): 4 | if(n%i) == 0: 5 | print("Number is not prime") 6 | break 7 | else: 8 | print("Number is prime") -------------------------------------------------------------------------------- /Chapter 7 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter the number: ")) 2 | i = 1 3 | sum = 0 4 | while(i<=n): 5 | sum += i 6 | i+=1 7 | 8 | print(sum) -------------------------------------------------------------------------------- /Chapter 7 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | # 5! = 1 X 2 X 3 X 4 X 5 2 | 3 | n = int(input("Enter the number: ")) 4 | product = 1 5 | for i in range(1, n+1): 6 | product = product * i 7 | 8 | print(f"The factorial of {n} is {product}") -------------------------------------------------------------------------------- /Chapter 7 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | ''' 2 | For n = 3 3 | * 4 | *** 5 | ***** 6 | 7 | For n = 5 8 | * 9 | *** 10 | ***** 11 | ******** 12 | ********** 13 | 14 | ''' 15 | 16 | n = int(input("Enter the number: ")) 17 | for i in range(1, n+1): 18 | print(" "* (n-i), end="") 19 | print("*"* (2*i-1), end="") 20 | print("") -------------------------------------------------------------------------------- /Chapter 7 - PS/08_problem8.py: -------------------------------------------------------------------------------- 1 | 2 | n = int(input("Enter the number: ")) 3 | for i in range(1, n+1): 4 | print("*"* i, end="") 5 | print("") -------------------------------------------------------------------------------- /Chapter 7 - PS/09_problem9.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | *** 4 | * * for n = 3 5 | *** 6 | 7 | 8 | ''' 9 | n = int(input("Enter the number: ")) 10 | for i in range(1, n+1): 11 | if(i==1 or i==n): 12 | print("*"* n, end="") 13 | else: 14 | print("*", end="") 15 | print(" "* (n-2), end="") 16 | print("*", end="") 17 | print("") -------------------------------------------------------------------------------- /Chapter 7 - PS/10_problem10.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter the number: ")) 2 | 3 | for i in range(1, 11): 4 | print(f"{n} X {11 -i} = {n*(11-i)}") 5 | 6 | -------------------------------------------------------------------------------- /Chapter 7/01_loops.py: -------------------------------------------------------------------------------- 1 | print(1) 2 | print(2) 3 | print(3) 4 | print(4) 5 | print(5) 6 | 7 | # The same task can be done like this: 8 | for i in range(1, 6): 9 | print(i) -------------------------------------------------------------------------------- /Chapter 7/02_while_loops.py: -------------------------------------------------------------------------------- 1 | i = 1 2 | 3 | while(i<51): 4 | print(i) 5 | i +=1 # or i = i + 1 6 | ''' 7 | Output: 8 | 1 9 | 2 10 | 3 11 | 4 12 | 5 13 | ''' 14 | -------------------------------------------------------------------------------- /Chapter 7/03_list_using_while.py: -------------------------------------------------------------------------------- 1 | l = [1, "Harry", False, "This", "Rohan", "Shubham", "Shubhi"] 2 | 3 | i = 0 4 | 5 | while(ib and a>c): 3 | return a 4 | elif(b>a and b>c): 5 | return b 6 | elif(c>b and c>a): 7 | return c 8 | 9 | a = 1 10 | b = 23 11 | c = 3 12 | 13 | print(greatest(a, b, c)) 14 | -------------------------------------------------------------------------------- /Chapter 8 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | def f_to_c(f): 2 | return 5*(f-32)/9 3 | 4 | f = int(input("Enter temperature in F: ")) 5 | c = f_to_c(f) 6 | print(f"{round(c, 2)}°C") -------------------------------------------------------------------------------- /Chapter 8 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | print("a") 2 | print("b") 3 | print("c", end="") 4 | print("d", end=""), -------------------------------------------------------------------------------- /Chapter 8 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | ''' 2 | sum(1) = 1 3 | sum(2) = 1 + 2 4 | sum(3) = 1 + 2 + 3 5 | sum(4) = 1 + 2 + 3 + 4 6 | sum(5) = 1 + 2 + 3 + 4 + 5 7 | 8 | sum(n) = 1 + 2 + 3 + 4.... n -1 + n 9 | sum(n) = sum(n-1) + n 10 | ''' 11 | 12 | def sum(n): 13 | if(n==1): 14 | return 1 15 | return sum(n-1) + n 16 | 17 | print(sum(4)) -------------------------------------------------------------------------------- /Chapter 8 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | if(n==0): 3 | return 4 | print("*" * n) 5 | pattern(n-1) 6 | 7 | 8 | pattern(3) -------------------------------------------------------------------------------- /Chapter 8 - PS/06_problem6.py: -------------------------------------------------------------------------------- 1 | def inch_to_cms(inch): 2 | return inch * 2.54 3 | 4 | n = int(input("Enter value in inches: ")) 5 | 6 | print(f"The corresponding value in cms is {inch_to_cms(n)}") 7 | -------------------------------------------------------------------------------- /Chapter 8 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | 2 | def rem(l, word): 3 | n = [] 4 | for item in l: 5 | if not(item == word): 6 | n.append(item.strip(word)) 7 | return n 8 | 9 | 10 | l = ["Harry", "Rohan", "Shubham", "an"] 11 | 12 | print(rem(l, "an")) -------------------------------------------------------------------------------- /Chapter 8 - PS/08_problem8.py: -------------------------------------------------------------------------------- 1 | def multiply(n): 2 | for i in range(1, 11): 3 | print(f"{n} X {i} = {n*i}") 4 | 5 | multiply(5) -------------------------------------------------------------------------------- /Chapter 8/01_functions.py: -------------------------------------------------------------------------------- 1 | # a = int(input("Enter your number: ")) 2 | # b = int(input("Enter your number: ")) 3 | # c = int(input("Enter your number: ")) 4 | 5 | # average = (a + b + c)/3 6 | # print(average) 7 | 8 | # a = int(input("Enter your number: ")) 9 | # b = int(input("Enter your number: ")) 10 | # c = int(input("Enter your number: ")) 11 | 12 | # average = (a + b + c)/3 13 | # print(average) 14 | 15 | # Function Definition 16 | def avg(): 17 | a = int(input("Enter your number: ")) 18 | b = int(input("Enter your number: ")) 19 | c = int(input("Enter your number: ")) 20 | 21 | average = (a + b + c)/3 22 | print(average) 23 | 24 | 25 | avg() # Function Call 26 | print("Thank you!") 27 | avg() 28 | print("Thank you!") 29 | avg() 30 | print("Thank you!") 31 | avg() 32 | avg() -------------------------------------------------------------------------------- /Chapter 8/02_quick_quiz.py: -------------------------------------------------------------------------------- 1 | def goodDay(): 2 | print("Good Day") 3 | 4 | goodDay() -------------------------------------------------------------------------------- /Chapter 8/03_function_with_arguments.py: -------------------------------------------------------------------------------- 1 | def goodDay(name, ending): 2 | print("Good Day, " + name) 3 | print(ending) 4 | return "ok" 5 | 6 | a = goodDay("Harry", "Thank you") 7 | print(a) -------------------------------------------------------------------------------- /Chapter 8/04_default_argument.py: -------------------------------------------------------------------------------- 1 | def goodDay(name, ending="Thank you"): 2 | print(f"Good Day, {name}") 3 | print(ending) 4 | 5 | goodDay("Harry", "Thanks") 6 | goodDay("Rohan") 7 | -------------------------------------------------------------------------------- /Chapter 8/05_recursion.py: -------------------------------------------------------------------------------- 1 | ''' 2 | factorial(0) = 1 3 | factorial(1) = 1 4 | factorial(2) = 2 X 1 5 | factorial(3) = 3 X 2 X 1 6 | factorial(4) = 4 X 3 X 2 X 1 7 | factorial(5) = 5 X 4 X 3 X 2 X 1 8 | factorial(n) = n X n-1 X......3 X 2 X 1 9 | 10 | factorial(n) = n * factorial(n-1) 11 | ''' 12 | 13 | def factorial(n): 14 | if(n==1 or n==0): 15 | return 1 16 | return n * factorial(n-1) 17 | 18 | 19 | n = int(input("Enter a number: ")) 20 | print(f"The factorial of this number is: {factorial(n)}") -------------------------------------------------------------------------------- /Chapter 9 - PS/01_problem1.py: -------------------------------------------------------------------------------- 1 | f = open("poem.txt") 2 | content = f.read() 3 | if("twinkle" in content): 4 | print("The word twinkle is present in the content") 5 | 6 | else: 7 | print("The word twinkle is not present in the content") 8 | 9 | f.close() -------------------------------------------------------------------------------- /Chapter 9 - PS/02_problem2.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def game(): 4 | print("You are playing the game..") 5 | score = random.randint(1, 62) 6 | # Fetch the hiscore 7 | with open("hiscore.txt") as f: 8 | hiscore = f.read() 9 | if(hiscore!=""): 10 | hiscore = int(hiscore) 11 | else: 12 | hiscore = 0 13 | 14 | print(f"Your score: {score}") 15 | if(score>hiscore): 16 | # write this hiscore to the file 17 | with open("hiscore.txt", "w") as f: 18 | f.write(str(score)) 19 | 20 | return score 21 | 22 | game() -------------------------------------------------------------------------------- /Chapter 9 - PS/03_problem3.py: -------------------------------------------------------------------------------- 1 | 2 | def generateTable(n): 3 | table = "" 4 | for i in range(1, 11): 5 | table += f"{n} X {i} = {n*i}\n" 6 | 7 | with open(f"tables/table_{n}.txt", "w") as f: 8 | f.write(table) 9 | 10 | 11 | 12 | 13 | for i in range(2, 21): 14 | generateTable(i) -------------------------------------------------------------------------------- /Chapter 9 - PS/04_problem4.py: -------------------------------------------------------------------------------- 1 | word = "Donkey" 2 | 3 | with open("file.txt", "r") as f: 4 | content = f.read() 5 | 6 | contentNew = content.replace(word, "######") 7 | 8 | with open("file.txt", "w") as f: 9 | f.write(contentNew) -------------------------------------------------------------------------------- /Chapter 9 - PS/05_problem5.py: -------------------------------------------------------------------------------- 1 | words = ["Donkey", "bad", "ganda"] 2 | 3 | with open("file.txt", "r") as f: 4 | content = f.read() 5 | 6 | for word in words: 7 | content = content.replace(word, "#" * len(word)) 8 | 9 | with open("file.txt", "w") as f: 10 | f.write(content) -------------------------------------------------------------------------------- /Chapter 9 - PS/06_problem.py: -------------------------------------------------------------------------------- 1 | with open("log.txt") as f: 2 | content = f.read() 3 | 4 | if("python" in content): 5 | print("Yes python is present") 6 | else: 7 | print("No Python is not present") -------------------------------------------------------------------------------- /Chapter 9 - PS/07_problem7.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | with open("log.txt") as f: 4 | lines = f.readlines() 5 | 6 | lineno = 1 7 | for line in lines: 8 | if("python" in line): 9 | print(f"Yes python is present. Line no: {lineno}") 10 | break 11 | lineno += 1 12 | 13 | else: 14 | print("No Python is not present") -------------------------------------------------------------------------------- /Chapter 9 - PS/08_problem8.py: -------------------------------------------------------------------------------- 1 | with open("this.txt") as f: 2 | content = f.read() 3 | 4 | with open("this_copy.txt", "w") as f: 5 | f.write(content) -------------------------------------------------------------------------------- /Chapter 9 - PS/09_problem9.py: -------------------------------------------------------------------------------- 1 | with open("this.txt") as f: 2 | content1 = f.read() 3 | 4 | with open("this_copy.txt") as f: 5 | content2 = f.read() 6 | 7 | if(content1 == content2): 8 | print("Yes these files are identical") 9 | 10 | else: 11 | print("No these files are not identical") -------------------------------------------------------------------------------- /Chapter 9 - PS/10_problem10.py: -------------------------------------------------------------------------------- 1 | with open("this_copy.txt", "w") as f: 2 | f.write("") -------------------------------------------------------------------------------- /Chapter 9 - PS/11_problem.py: -------------------------------------------------------------------------------- 1 | with open("old.txt") as f: 2 | content = f.read() 3 | 4 | with open("renamed_by_python.txt", "w") as f: 5 | f.write(content) -------------------------------------------------------------------------------- /Chapter 9 - PS/file.txt: -------------------------------------------------------------------------------- 1 | ###### is a nice ###### but not a ### ###### ##### 2 | bhai aap bahut hi ##### ho. ###### is good -------------------------------------------------------------------------------- /Chapter 9 - PS/hiscore.txt: -------------------------------------------------------------------------------- 1 | 45 -------------------------------------------------------------------------------- /Chapter 9 - PS/log.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatibus illo corrupti minima cupiditate? Molestias officiis doloribus architecto similique natus nesciunt, hic aspernatur fugit vitae! Placeat tempore suscipit deserunt, consequatur nobis reiciendis dolor dolorem sunt corporis minus labore! Animi quaerat optio nemo, similique, perspiciatis tenetur in nostrum unde eum porro officiis. Eum aperiam debitis sed cum tempore ipsam ex, fugit, voluptas beatae necessitatibus placeat deleniti porro tenetur non? Maxime voluptates, nostrum cupiditate reprehenderit error quod in ullam id tenetur perspiciatis beatae ex, sit dolores ducimus sint quos, qui blanditiis? Optio enim soluta ducimus quasi odio, ipsam voluptas mollitia debitis deserunt sapiente et harum suscipit eius. Excepturi, fugiat amet? Nulla 2 | 3 | python repellat magni libero, voluptatem, earum maxime animi sunt architecto harum atque asperiores provident dolores laborum itaque accusamus at. Aut voluptates numquam amet odit labore, similique eius minus quas unde asperiores cupiditate aliquam fugit rerum eligendi. Qui officia commodi maxime soluta quisquam exercitationem laboriosam sit amet, nisi officiis fugiat aut, obcaecati reiciendis culpa beatae dolore. Reiciendis numquam sunt ratione molestiae. Ea quas, tempora esse, pariatur voluptas adipisci tempore dicta quos harum non autem cumque exercitationem distinctio odio ex ipsa veritatis pytsdfhon dolores nam provident voluptatum officiis debitis quo. Dolores vel perspiciatis debitis ad error est voluptatem voluptatibus, quod fugiat optio, voluptate ea quos perferendis cupiditate doloremque architecto praesentium beatae libero officiis tempore cum temporibus illum totam tenetur! Dolores cum deserunt delectus earum nostrum inventore dignissimos error harum aspernatur consequatur numquam itaque architecto, rerum quaerat natus quae saepe? Ratione nam et explicabo ex quis architecto, dolores voluptate consequatur perspiciatis sapiente voluptatem fuga vitae ut blanditiis numquam quibusdam error velit id laudantium reiciendis. At, voluptatibus voluptates alias exercitationem ipsam voluptate itaque aut molestias similique repudiandae deleniti nam omnis voluptas possimus. Maxime iste minima quod maiores facilis ipsam, vero eveniet aperiam assumenda blanditiis esse nostrum fugiat veniam vel ullam obcaecati dicta. Non error nisi necessitatibus facilis, blanditiis illo quisquam doloremque quis enim recusandae tenetur corporis molestias repudiandae iste, perferendis asperiores ea eligendi, reprehenderit autem. Ipsum optio dignissimos cum qui, ut quia praesentium vitae incidunt similique aut beatae est? Ab sit unde debitis expedita minus reprehenderit laudantium laboriosam, alias eveniet beatae consequuntur cupiditate in quibusdam similique dolores tempora. Sunt ex officiis amet rem voluptas nobis quidem, harum deserunt, laborum cum vel aut dignissimos reiciendis architecto consequuntur assumenda odio et! Porro nam aliquam officia optio, sint quis minus, quam nesciunt alias eum mollitia ipsum saepe dolor similique. Sunt et repellat est illo. At commodi deserunt natus eum consequuntur? Enim at voluptates, excepturi est nulla praesentium laboriosam temporibus rerum aut vitae hic quam deserunt commodi facilis officia soluta sed, inventore, dolorum eius. Magni, eaque expedita. -------------------------------------------------------------------------------- /Chapter 9 - PS/old.txt: -------------------------------------------------------------------------------- 1 | I am old -------------------------------------------------------------------------------- /Chapter 9 - PS/poem.txt: -------------------------------------------------------------------------------- 1 | twinkle twinkle little star 2 | Kaise ho mere bhai log yaar -------------------------------------------------------------------------------- /Chapter 9 - PS/renamed_by_python.txt: -------------------------------------------------------------------------------- 1 | I am old -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_10.txt: -------------------------------------------------------------------------------- 1 | 10 X 1 = 10 2 | 10 X 2 = 20 3 | 10 X 3 = 30 4 | 10 X 4 = 40 5 | 10 X 5 = 50 6 | 10 X 6 = 60 7 | 10 X 7 = 70 8 | 10 X 8 = 80 9 | 10 X 9 = 90 10 | 10 X 10 = 100 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_11.txt: -------------------------------------------------------------------------------- 1 | 11 X 1 = 11 2 | 11 X 2 = 22 3 | 11 X 3 = 33 4 | 11 X 4 = 44 5 | 11 X 5 = 55 6 | 11 X 6 = 66 7 | 11 X 7 = 77 8 | 11 X 8 = 88 9 | 11 X 9 = 99 10 | 11 X 10 = 110 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_12.txt: -------------------------------------------------------------------------------- 1 | 12 X 1 = 12 2 | 12 X 2 = 24 3 | 12 X 3 = 36 4 | 12 X 4 = 48 5 | 12 X 5 = 60 6 | 12 X 6 = 72 7 | 12 X 7 = 84 8 | 12 X 8 = 96 9 | 12 X 9 = 108 10 | 12 X 10 = 120 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_13.txt: -------------------------------------------------------------------------------- 1 | 13 X 1 = 13 2 | 13 X 2 = 26 3 | 13 X 3 = 39 4 | 13 X 4 = 52 5 | 13 X 5 = 65 6 | 13 X 6 = 78 7 | 13 X 7 = 91 8 | 13 X 8 = 104 9 | 13 X 9 = 117 10 | 13 X 10 = 130 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_14.txt: -------------------------------------------------------------------------------- 1 | 14 X 1 = 14 2 | 14 X 2 = 28 3 | 14 X 3 = 42 4 | 14 X 4 = 56 5 | 14 X 5 = 70 6 | 14 X 6 = 84 7 | 14 X 7 = 98 8 | 14 X 8 = 112 9 | 14 X 9 = 126 10 | 14 X 10 = 140 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_15.txt: -------------------------------------------------------------------------------- 1 | 15 X 1 = 15 2 | 15 X 2 = 30 3 | 15 X 3 = 45 4 | 15 X 4 = 60 5 | 15 X 5 = 75 6 | 15 X 6 = 90 7 | 15 X 7 = 105 8 | 15 X 8 = 120 9 | 15 X 9 = 135 10 | 15 X 10 = 150 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_16.txt: -------------------------------------------------------------------------------- 1 | 16 X 1 = 16 2 | 16 X 2 = 32 3 | 16 X 3 = 48 4 | 16 X 4 = 64 5 | 16 X 5 = 80 6 | 16 X 6 = 96 7 | 16 X 7 = 112 8 | 16 X 8 = 128 9 | 16 X 9 = 144 10 | 16 X 10 = 160 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_17.txt: -------------------------------------------------------------------------------- 1 | 17 X 1 = 17 2 | 17 X 2 = 34 3 | 17 X 3 = 51 4 | 17 X 4 = 68 5 | 17 X 5 = 85 6 | 17 X 6 = 102 7 | 17 X 7 = 119 8 | 17 X 8 = 136 9 | 17 X 9 = 153 10 | 17 X 10 = 170 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_18.txt: -------------------------------------------------------------------------------- 1 | 18 X 1 = 18 2 | 18 X 2 = 36 3 | 18 X 3 = 54 4 | 18 X 4 = 72 5 | 18 X 5 = 90 6 | 18 X 6 = 108 7 | 18 X 7 = 126 8 | 18 X 8 = 144 9 | 18 X 9 = 162 10 | 18 X 10 = 180 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_19.txt: -------------------------------------------------------------------------------- 1 | 19 X 1 = 19 2 | 19 X 2 = 38 3 | 19 X 3 = 57 4 | 19 X 4 = 76 5 | 19 X 5 = 95 6 | 19 X 6 = 114 7 | 19 X 7 = 133 8 | 19 X 8 = 152 9 | 19 X 9 = 171 10 | 19 X 10 = 190 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_2.txt: -------------------------------------------------------------------------------- 1 | 2 X 1 = 2 2 | 2 X 2 = 4 3 | 2 X 3 = 6 4 | 2 X 4 = 8 5 | 2 X 5 = 10 6 | 2 X 6 = 12 7 | 2 X 7 = 14 8 | 2 X 8 = 16 9 | 2 X 9 = 18 10 | 2 X 10 = 20 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_20.txt: -------------------------------------------------------------------------------- 1 | 20 X 1 = 20 2 | 20 X 2 = 40 3 | 20 X 3 = 60 4 | 20 X 4 = 80 5 | 20 X 5 = 100 6 | 20 X 6 = 120 7 | 20 X 7 = 140 8 | 20 X 8 = 160 9 | 20 X 9 = 180 10 | 20 X 10 = 200 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_3.txt: -------------------------------------------------------------------------------- 1 | 3 X 1 = 3 2 | 3 X 2 = 6 3 | 3 X 3 = 9 4 | 3 X 4 = 12 5 | 3 X 5 = 15 6 | 3 X 6 = 18 7 | 3 X 7 = 21 8 | 3 X 8 = 24 9 | 3 X 9 = 27 10 | 3 X 10 = 30 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_4.txt: -------------------------------------------------------------------------------- 1 | 4 X 1 = 4 2 | 4 X 2 = 8 3 | 4 X 3 = 12 4 | 4 X 4 = 16 5 | 4 X 5 = 20 6 | 4 X 6 = 24 7 | 4 X 7 = 28 8 | 4 X 8 = 32 9 | 4 X 9 = 36 10 | 4 X 10 = 40 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_5.txt: -------------------------------------------------------------------------------- 1 | 5 X 1 = 5 2 | 5 X 2 = 10 3 | 5 X 3 = 15 4 | 5 X 4 = 20 5 | 5 X 5 = 25 6 | 5 X 6 = 30 7 | 5 X 7 = 35 8 | 5 X 8 = 40 9 | 5 X 9 = 45 10 | 5 X 10 = 50 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_6.txt: -------------------------------------------------------------------------------- 1 | 6 X 1 = 6 2 | 6 X 2 = 12 3 | 6 X 3 = 18 4 | 6 X 4 = 24 5 | 6 X 5 = 30 6 | 6 X 6 = 36 7 | 6 X 7 = 42 8 | 6 X 8 = 48 9 | 6 X 9 = 54 10 | 6 X 10 = 60 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_7.txt: -------------------------------------------------------------------------------- 1 | 7 X 1 = 7 2 | 7 X 2 = 14 3 | 7 X 3 = 21 4 | 7 X 4 = 28 5 | 7 X 5 = 35 6 | 7 X 6 = 42 7 | 7 X 7 = 49 8 | 7 X 8 = 56 9 | 7 X 9 = 63 10 | 7 X 10 = 70 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_8.txt: -------------------------------------------------------------------------------- 1 | 8 X 1 = 8 2 | 8 X 2 = 16 3 | 8 X 3 = 24 4 | 8 X 4 = 32 5 | 8 X 5 = 40 6 | 8 X 6 = 48 7 | 8 X 7 = 56 8 | 8 X 8 = 64 9 | 8 X 9 = 72 10 | 8 X 10 = 80 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/tables/table_9.txt: -------------------------------------------------------------------------------- 1 | 9 X 1 = 9 2 | 9 X 2 = 18 3 | 9 X 3 = 27 4 | 9 X 4 = 36 5 | 9 X 5 = 45 6 | 9 X 6 = 54 7 | 9 X 7 = 63 8 | 9 X 8 = 72 9 | 9 X 9 = 81 10 | 9 X 10 = 90 11 | -------------------------------------------------------------------------------- /Chapter 9 - PS/this.txt: -------------------------------------------------------------------------------- 1 | hey mai this hooon 2 | muje bahut maze aa rahe hain 3 | mai maze me aa rha hu -------------------------------------------------------------------------------- /Chapter 9 - PS/this_copy.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Chapter 9 - PS/this_copy.txt -------------------------------------------------------------------------------- /Chapter 9/01_file.py: -------------------------------------------------------------------------------- 1 | ''' 2 | a = "a very long string with emails" 3 | 4 | emails = [] 5 | 3 seconds 6 | ''' 7 | 8 | f = open("file.txt", "r") 9 | data = f.read() 10 | print(data) 11 | f.close() -------------------------------------------------------------------------------- /Chapter 9/02_file_write.py: -------------------------------------------------------------------------------- 1 | st = "Hey Harry you are amazing" 2 | 3 | f = open("myfile.txt", "w") 4 | 5 | f.write(st) 6 | 7 | f.close() -------------------------------------------------------------------------------- /Chapter 9/03_more_file_functions.py: -------------------------------------------------------------------------------- 1 | f = open("file.txt") 2 | 3 | # lines = f.readlines() 4 | # print(lines, type(lines)) 5 | 6 | # line1 = f.readline() 7 | # print(line1, type(line1)) 8 | 9 | # line2 = f.readline() 10 | # print(line2, type(line2)) 11 | 12 | # line3 = f.readline() 13 | # print(line3, type(line3)) 14 | 15 | # line4 = f.readline() 16 | # print(line4, type(line4)) 17 | 18 | # line5 = f.readline() 19 | # print(line5 =="") 20 | line = f.readline() 21 | while(line != ""): 22 | print(line) 23 | line = f.readline() 24 | 25 | f.close() -------------------------------------------------------------------------------- /Chapter 9/04_append.py: -------------------------------------------------------------------------------- 1 | st = "Hey Harry you are amazing" 2 | 3 | f = open("myfile.txt", "a") 4 | 5 | f.write(st) 6 | 7 | f.close() -------------------------------------------------------------------------------- /Chapter 9/05_with.py: -------------------------------------------------------------------------------- 1 | f = open("file.txt") 2 | print(f.read()) 3 | f.close() 4 | 5 | # The same can be written using with statement like this: 6 | with open("file.txt") as f: 7 | print(f.read()) 8 | 9 | # You dont have to explicitly close the file -------------------------------------------------------------------------------- /Chapter 9/file.txt: -------------------------------------------------------------------------------- 1 | Harry is a good boy 2 | I am a second line 3 | This is amazing 4 | Twinkle Twinkle little star -------------------------------------------------------------------------------- /Chapter 9/myfile.txt: -------------------------------------------------------------------------------- 1 | Hey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazingHey Harry you are amazing -------------------------------------------------------------------------------- /HandWritten_Python_Complete_Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/HandWritten_Python_Complete_Notes.pdf -------------------------------------------------------------------------------- /Mega Project 1 - Jarvis/client.py: -------------------------------------------------------------------------------- 1 | from openai import OpenAI 2 | 3 | # pip install openai 4 | # if you saved the key under a different environment variable name, you can do something like: 5 | client = OpenAI( 6 | api_key="", 7 | ) 8 | 9 | completion = client.chat.completions.create( 10 | model="gpt-3.5-turbo", 11 | messages=[ 12 | {"role": "system", "content": "You are a virtual assistant named jarvis skilled in general tasks like Alexa and Google Cloud"}, 13 | {"role": "user", "content": "what is coding"} 14 | ] 15 | ) 16 | 17 | print(completion.choices[0].message.content) -------------------------------------------------------------------------------- /Mega Project 1 - Jarvis/main.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | import webbrowser 3 | import pyttsx3 4 | import musicLibrary 5 | import requests 6 | from openai import OpenAI 7 | from gtts import gTTS 8 | import pygame 9 | import os 10 | 11 | # pip install pocketsphinx 12 | 13 | recognizer = sr.Recognizer() 14 | engine = pyttsx3.init() 15 | newsapi = "" 16 | 17 | def speak_old(text): 18 | engine.say(text) 19 | engine.runAndWait() 20 | 21 | def speak(text): 22 | tts = gTTS(text) 23 | tts.save('temp.mp3') 24 | 25 | # Initialize Pygame mixer 26 | pygame.mixer.init() 27 | 28 | # Load the MP3 file 29 | pygame.mixer.music.load('temp.mp3') 30 | 31 | # Play the MP3 file 32 | pygame.mixer.music.play() 33 | 34 | # Keep the program running until the music stops playing 35 | while pygame.mixer.music.get_busy(): 36 | pygame.time.Clock().tick(10) 37 | 38 | pygame.mixer.music.unload() 39 | os.remove("temp.mp3") 40 | 41 | def aiProcess(command): 42 | client = OpenAI(api_key="", 43 | ) 44 | 45 | completion = client.chat.completions.create( 46 | model="gpt-3.5-turbo", 47 | messages=[ 48 | {"role": "system", "content": "You are a virtual assistant named jarvis skilled in general tasks like Alexa and Google Cloud. Give short responses please"}, 49 | {"role": "user", "content": command} 50 | ] 51 | ) 52 | 53 | return completion.choices[0].message.content 54 | 55 | def processCommand(c): 56 | if "open google" in c.lower(): 57 | webbrowser.open("https://google.com") 58 | elif "open facebook" in c.lower(): 59 | webbrowser.open("https://facebook.com") 60 | elif "open youtube" in c.lower(): 61 | webbrowser.open("https://youtube.com") 62 | elif "open linkedin" in c.lower(): 63 | webbrowser.open("https://linkedin.com") 64 | elif c.lower().startswith("play"): 65 | song = c.lower().split(" ")[1] 66 | link = musicLibrary.music[song] 67 | webbrowser.open(link) 68 | 69 | elif "news" in c.lower(): 70 | r = requests.get(f"https://newsapi.org/v2/top-headlines?country=in&apiKey={newsapi}") 71 | if r.status_code == 200: 72 | # Parse the JSON response 73 | data = r.json() 74 | 75 | # Extract the articles 76 | articles = data.get('articles', []) 77 | 78 | # Print the headlines 79 | for article in articles: 80 | speak(article['title']) 81 | 82 | else: 83 | # Let OpenAI handle the request 84 | output = aiProcess(c) 85 | speak(output) 86 | 87 | 88 | 89 | 90 | 91 | if __name__ == "__main__": 92 | speak("Initializing Jarvis....") 93 | while True: 94 | # Listen for the wake word "Jarvis" 95 | # obtain audio from the microphone 96 | r = sr.Recognizer() 97 | 98 | print("recognizing...") 99 | try: 100 | with sr.Microphone() as source: 101 | print("Listening...") 102 | audio = r.listen(source, timeout=2, phrase_time_limit=1) 103 | word = r.recognize_google(audio) 104 | if(word.lower() == "jarvis"): 105 | speak("Ya") 106 | # Listen for command 107 | with sr.Microphone() as source: 108 | print("Jarvis Active...") 109 | audio = r.listen(source) 110 | command = r.recognize_google(audio) 111 | 112 | processCommand(command) 113 | 114 | 115 | except Exception as e: 116 | print("Error; {0}".format(e)) 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Mega Project 1 - Jarvis/musicLibrary.py: -------------------------------------------------------------------------------- 1 | music = { 2 | "stealth": "https://www.youtube.com/watch?v=U47Tr9BB_wE", 3 | "march": "https://www.youtube.com/watch?v=Xqeq4b5u_Xw", 4 | "skyfall": "https://www.youtube.com/watch?v=DeumyOzKqgI&pp=ygUHc2t5ZmFsbA%3D%3D", 5 | "wolf": "https://www.youtube.com/watch?v=ThCH0U6aJpU&list=PLnrGi_-oOR6wm0Vi-1OsiLiV5ePSPs9oF&index=21" 6 | } -------------------------------------------------------------------------------- /Mega Project 1 - Jarvis/temp.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeWithHarry/The-Ultimate-Python-Course/19865a0acd48c4b093ef81ead7fa190a0f99db69/Mega Project 1 - Jarvis/temp.mp3 -------------------------------------------------------------------------------- /Mega Project 2 - AI AutoReply Bot/01_get_cursor.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | 3 | while True: 4 | a = pyautogui.position() 5 | print(a) 6 | # 1639, 1412 7 | # 1003 237 to 2187 1258 8 | # 1026 244 9 | # to 1131 1321 -------------------------------------------------------------------------------- /Mega Project 2 - AI AutoReply Bot/02_openai.py: -------------------------------------------------------------------------------- 1 | from openai import OpenAI 2 | 3 | # pip install openai 4 | # if you saved the key under a different environment variable name, you can do something like: 5 | client = OpenAI( 6 | api_key="", 7 | ) 8 | 9 | command = ''' 10 | [20:30, 12/6/2024] Naruto: jo sunke coding ho sake? 11 | [20:30, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=DzmG-4-OASQ 12 | [20:30, 12/6/2024] Rohan Das: ye 13 | [20:30, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=DzmG-4-OASQ 14 | [20:31, 12/6/2024] Naruto: This is hindi 15 | [20:31, 12/6/2024] Naruto: send me some english songs 16 | [20:31, 12/6/2024] Naruto: but wait 17 | [20:31, 12/6/2024] Naruto: this song is amazing 18 | [20:31, 12/6/2024] Naruto: so I will stick to it 19 | [20:31, 12/6/2024] Naruto: send me some english song also 20 | [20:31, 12/6/2024] Rohan Das: hold on 21 | [20:31, 12/6/2024] Naruto: I know what you are about to send 22 | [20:32, 12/6/2024] Naruto: 😂😂 23 | [20:32, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=ar-3chBG4NU 24 | ye hindi English mix hai but best hai 25 | [20:33, 12/6/2024] Naruto: okok 26 | [20:33, 12/6/2024] Rohan Das: Haan 27 | ''' 28 | completion = client.chat.completions.create( 29 | model="gpt-3.5-turbo", 30 | messages=[ 31 | {"role": "system", "content": "You are a person named harry who speaks hindi as well as english. He is from India and is a coder. You analyze chat history and respond like Harry"}, 32 | {"role": "user", "content": command} 33 | ] 34 | ) 35 | 36 | print(completion.choices[0].message.content) -------------------------------------------------------------------------------- /Mega Project 2 - AI AutoReply Bot/03_bot.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | import time 3 | import pyperclip 4 | from openai import OpenAI 5 | 6 | 7 | 8 | 9 | client = OpenAI( 10 | api_key="", 11 | ) 12 | 13 | def is_last_message_from_sender(chat_log, sender_name="Rohan Das"): 14 | # Split the chat log into individual messages 15 | messages = chat_log.strip().split("/2024] ")[-1] 16 | if sender_name in messages: 17 | return True 18 | return False 19 | 20 | 21 | 22 | # Step 1: Click on the chrome icon at coordinates (1639, 1412) 23 | pyautogui.click(1639, 1412) 24 | 25 | time.sleep(1) # Wait for 1 second to ensure the click is registered 26 | while True: 27 | time.sleep(5) 28 | # Step 2: Drag the mouse from (1003, 237) to (2187, 1258) to select the text 29 | pyautogui.moveTo(972,202) 30 | pyautogui.dragTo(2213, 1278, duration=2.0, button='left') # Drag for 1 second 31 | 32 | # Step 3: Copy the selected text to the clipboard 33 | pyautogui.hotkey('ctrl', 'c') 34 | time.sleep(2) # Wait for 1 second to ensure the copy command is completed 35 | pyautogui.click(1994, 281) 36 | 37 | # Step 4: Retrieve the text from the clipboard and store it in a variable 38 | chat_history = pyperclip.paste() 39 | 40 | # Print the copied text to verify 41 | print(chat_history) 42 | print(is_last_message_from_sender(chat_history)) 43 | if is_last_message_from_sender(chat_history): 44 | completion = client.chat.completions.create( 45 | model="gpt-3.5-turbo", 46 | messages=[ 47 | {"role": "system", "content": "You are a person named Naruto who speaks hindi as well as english. You are from India and you are a coder. You analyze chat history and roast people in a funny way. Output should be the next chat response (text message only)"}, 48 | {"role": "system", "content": "Do not start like this [21:02, 12/6/2024] Rohan Das: "}, 49 | {"role": "user", "content": chat_history} 50 | ] 51 | ) 52 | 53 | response = completion.choices[0].message.content 54 | pyperclip.copy(response) 55 | 56 | # Step 5: Click at coordinates (1808, 1328) 57 | pyautogui.click(1808, 1328) 58 | time.sleep(1) # Wait for 1 second to ensure the click is registered 59 | 60 | # Step 6: Paste the text 61 | pyautogui.hotkey('ctrl', 'v') 62 | time.sleep(1) # Wait for 1 second to ensure the paste command is completed 63 | 64 | # Step 7: Press Enter 65 | pyautogui.press('enter') -------------------------------------------------------------------------------- /Project 1/main-shortened.py: -------------------------------------------------------------------------------- 1 | import random 2 | ''' 3 | 1 for snake 4 | -1 for water 5 | 0 for gun 6 | ''' 7 | computer = random.choice([-1, 0, 1]) 8 | youstr = input("Enter your choice: ") 9 | youDict = {"s": 1, "w": -1, "g": 0} 10 | reverseDict = {1: "Snake", -1: "Water", 0: "Gun"} 11 | 12 | you = youDict[youstr] 13 | 14 | # By now we have 2 numbers (variables), you and computer 15 | 16 | print(f"You chose {reverseDict[you]}\nComputer chose {reverseDict[computer]}") 17 | 18 | if(computer == you): 19 | print("Its a draw") 20 | 21 | else: 22 | ''' 23 | if(computer ==-1 and you == 1): (computer - you) = -2 24 | print("You win!") 25 | 26 | elif(computer ==-1 and you == 0): (computer - you) = -1 27 | print("You Lose!") 28 | 29 | elif(computer == 1 and you == -1): (computer - you) = 2 30 | print("You lose!") 31 | 32 | elif(computer ==1 and you == 0): (computer - you) = 1 33 | print("You Win!") 34 | 35 | elif(computer ==0 and you == -1): (computer - you) = 1 36 | print("You Win!") 37 | 38 | elif(computer == 0 and you == 1): computer - you) = -1 39 | print("You Lose!") 40 | 41 | The below logic is written on the basis of the value of computer - you 42 | 43 | ''' 44 | if((computer - you) == -1 or (computer - you) == 2 ): 45 | print("You lose!") 46 | else: 47 | print("You win!") -------------------------------------------------------------------------------- /Project 1/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | ''' 3 | 1 for snake 4 | -1 for water 5 | 0 for gun 6 | ''' 7 | computer = random.choice([-1, 0, 1]) 8 | youstr = input("Enter your choice: ") 9 | youDict = {"s": 1, "w": -1, "g": 0} 10 | reverseDict = {1: "Snake", -1: "Water", 0: "Gun"} 11 | 12 | you = youDict[youstr] 13 | 14 | # By now we have 2 numbers (variables), you and computer 15 | 16 | print(f"You chose {reverseDict[you]}\nComputer chose {reverseDict[computer]}") 17 | 18 | if(computer == you): 19 | print("Its a draw") 20 | 21 | else: 22 | if(computer ==-1 and you == 1): 23 | print("You win!") 24 | 25 | elif(computer ==-1 and you == 0): 26 | print("You Lose!") 27 | 28 | elif(computer == 1 and you == -1): 29 | print("You lose!") 30 | 31 | elif(computer ==1 and you == 0): 32 | print("You Win!") 33 | 34 | elif(computer ==0 and you == -1): 35 | print("You Win!") 36 | 37 | elif(computer == 0 and you == 1): 38 | print("You Lose!") 39 | 40 | else: 41 | print("Something went wrong!") -------------------------------------------------------------------------------- /Project 2/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | n = random.randint(1, 100) 3 | a = -1 4 | guesses = 1 5 | while(a != n): 6 | a = int(input("Guess the number: ")) 7 | if(a >n): 8 | print("Lower number please") 9 | guesses +=1 10 | elif(a