├── 01_Hello.py ├── 02_Strings.py ├── 03_PlaysoundModule.py ├── 04_ListingDirectories.py ├── 05_Variable.py ├── 06_Operators.py ├── 07_Typecating.py ├── 08_InputFunction.py ├── 09_AdditionCalculator.py ├── 100_pr01ch10.py ├── 101_pr02ch10.py ├── 102_pr03ch10.py ├── 103_pr04ch10.py ├── 104_pr05ch10.py ├── 105_pr06ch10.py ├── 106_Single_inheritence.py ├── 107_ multiple_inheritance.py ├── 108_multi_level_inheritance.py ├── 109_super_meathod.py ├── 10_RemainderCalculator.py ├── 110_class_meathods.py ├── 111_property_decorator.py ├── 112_operator_overloading.py ├── 113_OtherDunderMeathods.py ├── 114_pr01ch11.py ├── 115_pr02ch11.py ├── 116_pr03ch11.py ├── 117_pr04ch11.py ├── 118_pro5ch11.py ├── 119_pr06ch11.py ├── 11_AvgCalculator.py ├── 120_pr07ch11.py ├── 121_GuessTheNumber_Game.py ├── 122_highscore.txt ├── 12_StringUsage.py ├── 13_StringSlicing.py ├── 14_StringFunctions.py ├── 15_EscapeSequences.py ├── 16_pr_01_ch3.py ├── 17_pr_02ch3.py ├── 19_pr_03ch3.py ├── 20_pr_04ch3.py ├── 21_pr_05ch3.py ├── 22_List=[ ].py ├── 23_Tuple( ).py ├── 24_TupleMethods.py ├── 25_pr_Fruits.py ├── 26_pr_Marks.py ├── 27_pr_Sum_of_a_List.py ├── 28_Dictionary{ }.py ├── 29_DictionaryMethods.py ├── 30_Sets{ }.py ├── 31_EmptySet( ).py ├── 32_SetsMeathods.py ├── 33_pr_ch5.py ├── 34_pr_ch5.py ├── 35_pr_ch5.py ├── 36_pr06_ch5.py ├── 37_Conditionals.py ├── 38_NotesQuiz.py ├── 39_in_and_is.py ├── 40_ElseOptional.py ├── 41_pr01_ch6.py ├── 42_pr02_ch6.py ├── 43_pr03_ch6.py ├── 44_pr05_ch6.py ├── 45_pr06_ch6.py ├── 46_WhileLoop.py ├── 47_print(Num)-WhileLoop.py ├── 48_Loops_Ex.py ├── 49_ListLoops.py ├── 50_print(list)-forLoop.py ├── 51_RangeFunction.py ├── 52_for_with_else.py ├── 53_BreakStatement.py ├── 54_ContinueStatement.py ├── 55_PassStatement.py ├── 56_pr_01ch7.py ├── 57_pr02ch7.py ├── 58_pr04ch7.py ├── 59_pr06ch7.py ├── 60_pr07_StarPattern.py ├── 61_pr08ch7_StarPattern.py ├── 62_Functions.py ├── 62_QuickQuiz.py ├── 63_DefaultArguements.py ├── 64_Recursion.py ├── 65_pr01ch8.py ├── 66_pr02ch8.py ├── 67_pr03ch8.py ├── 68_pr05ch8_StarTattern.py ├── 69_pr07.py ├── 70_snake_water_gun_Game.py ├── 71_Files.py ├── 72_Sample.txt ├── 73_Readline.py ├── 74_Write.py ├── 75_Another.txt ├── 76_with_Statement.py ├── 77_pr01ch9.py ├── 78_Poems.txt ├── 79_pr02ch9_code.py ├── 80_Highscore.txt ├── 82_pr04ch9.py ├── 83_pr05ch9.py ├── 84_logfilefrom_ibm.txt ├── 85_pr06ch9.py ├── 86_pr07ch9.py ├── 87_this.txt ├── 88_copy.txt ├── 89_pr08ch9.py ├── 90_pr09ch9.py ├── 91_pr10ch9.py ├── 92_pr11ch9.py ├── 93_oops.py ├── 94_railway_oops.py ├── 95_game_example.py ├── 96_employee.py ├── 97_instance_class-attribrutes.py ├── 98_self.py ├── 99_constructor.py ├── LICENSE ├── README.md └── pr02ch9 ├── multipulication_table_of_10.txt ├── multipulication_table_of_11.txt ├── multipulication_table_of_12.txt ├── multipulication_table_of_13.txt ├── multipulication_table_of_14.txt ├── multipulication_table_of_15.txt ├── multipulication_table_of_16.txt ├── multipulication_table_of_17.txt ├── multipulication_table_of_18.txt ├── multipulication_table_of_19.txt ├── multipulication_table_of_2.txt ├── multipulication_table_of_20.txt ├── multipulication_table_of_3.txt ├── multipulication_table_of_4.txt ├── multipulication_table_of_5.txt ├── multipulication_table_of_6.txt ├── multipulication_table_of_7.txt ├── multipulication_table_of_8.txt └── multipulication_table_of_9.txt /01_Hello.py: -------------------------------------------------------------------------------- 1 | '''Author: Aniket 2 | Licenced to : ABC Company 3 | ****thanks for reading**** 4 | ''' 5 | import os # importing the os module 6 | 7 | print("hello world") 8 | -------------------------------------------------------------------------------- /02_Strings.py: -------------------------------------------------------------------------------- 1 | # STRING 2 | 3 | '''this is soln of q1 of practise set''' 4 | 5 | 6 | print('''Twinkle, twinkle, little star, 7 | How I wonder what you are! 8 | Up above the world so high, 9 | Like a diamond in the sky.''') 10 | # IN LINE 7 LEAVE SPACE DOESENT STARTS TEXT INLINE WITH LINE 6. 11 | -------------------------------------------------------------------------------- /03_PlaysoundModule.py: -------------------------------------------------------------------------------- 1 | from playsound import playsound 2 | playsound("C:\\Users\\anike\\OneDrive\\Desktop\\Sample Music\\mp1.mp3") 3 | # "C:\Users\anike\OneDrive\Desktop\Sample Music\mp2.mp3" -------------------------------------------------------------------------------- /04_ListingDirectories.py: -------------------------------------------------------------------------------- 1 | # Author:Aniket 2 | # location:Mars 3 | # Date:27/0/2022 4 | 5 | import os 6 | print(os.listdir()) 7 | # lists all dirrectories -------------------------------------------------------------------------------- /05_Variable.py: -------------------------------------------------------------------------------- 1 | # variables 2 | 3 | a= "aniket" 4 | b_212=345 5 | c=45.32 6 | d='''raju is learning python''' 7 | 8 | # Printing the variable. 9 | print(a) 10 | print(b_212) 11 | print(c) 12 | print(d) 13 | 14 | # class(bool):- 15 | e= True 16 | f= False 17 | g= None 18 | 19 | # Printing the type of variables 20 | print(type(a)) 21 | print(type(b_212)) 22 | print(type(c)) 23 | 24 | C=23.34 25 | 26 | print(e) 27 | print(type(e)) -------------------------------------------------------------------------------- /06_Operators.py: -------------------------------------------------------------------------------- 1 | # operators in python 2 | 3 | a = 3 4 | b = 4 5 | 6 | # Airthematic operator 7 | print("The value of 3+4 is ", 3+4) 8 | print("The value of 3-4 is ", 3-4) 9 | print("The value of 3*4 is ", 3*4) 10 | 11 | # Assignment operators(you can overite vaiables) 12 | a = 2 13 | a +=2 14 | print(a) 15 | 16 | # Comparision operator 17 | B = (4>9) 18 | print(B) 19 | 20 | # Logical operators 21 | bool1 = True 22 | bool2 = False 23 | print("the value of bool1 and bool2 is ", (bool1 and bool2)) 24 | print("the value of bool1 or bool2 is ", (bool1 or bool2)) 25 | print("the value of not bool2 is ", (not bool2)) 26 | -------------------------------------------------------------------------------- /07_Typecating.py: -------------------------------------------------------------------------------- 1 | # typecasting:- 2 | 3 | a = "3534" 4 | print(type(a)) 5 | 6 | # print(a+5) throws error 7 | 8 | a = int(a) # changing variable type of (a). 9 | print(type(a)) 10 | 11 | print(a+5) 12 | -------------------------------------------------------------------------------- /08_InputFunction.py: -------------------------------------------------------------------------------- 1 | # INPUT FUNCTION 2 | 3 | """very important:- 4 | input function always requires a string to avoid deadlock error. 5 | """ 6 | 7 | a = input("Enter your number: ") 8 | 9 | a = int(a) # Convert a to an integer (if possible) 10 | print(type(a)) 11 | print(a) 12 | -------------------------------------------------------------------------------- /09_AdditionCalculator.py: -------------------------------------------------------------------------------- 1 | # ADDITION CALCULATOR 2 | 3 | a=34 4 | b=5 5 | print("The sum of a and b is ", a+b) 6 | -------------------------------------------------------------------------------- /100_pr01ch10.py: -------------------------------------------------------------------------------- 1 | class Programmer: 2 | company = "microsoft" 3 | 4 | def __init__(self, name, product) : 5 | self.name = name 6 | self.product = product 7 | 8 | def getInfo(self): 9 | print(f"the name oftthe company is {self.company}.\n The name of the programmer is {self.name} \n and product is {self.product}.") 10 | 11 | harry = Programmer("harry", "skype") 12 | alka = Programmer("alka", "github") 13 | harry.getInfo() 14 | -------------------------------------------------------------------------------- /101_pr02ch10.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def __init__(self, num) : 3 | self.number = num 4 | 5 | def square(self): 6 | print(f"the value of {self.number} is {self.number**2}") 7 | 8 | def squareRoot(self): 9 | print(f"the value of {self.number} is {self.number**0.5}") 10 | 11 | def cube(self): 12 | print(f"the value of {self.number} is {self.number**3}") 13 | 14 | a = Calculator(3) 15 | a.square() 16 | a.squareRoot() 17 | a.cube() 18 | -------------------------------------------------------------------------------- /102_pr03ch10.py: -------------------------------------------------------------------------------- 1 | class Sample: 2 | a = "harry" 3 | 4 | obj = Sample() 5 | obj.a = "vikky" 6 | # Sample.a = "vikky" 7 | 8 | print(Sample.a) 9 | print(obj.a) -------------------------------------------------------------------------------- /103_pr04ch10.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def __init__(self, num) : 3 | self.number = num 4 | 5 | def square(self): 6 | print(f"the value of {self.number} is {self.number**2}") 7 | 8 | def squareRoot(self): 9 | print(f"the value of {self.number} is {self.number**0.5}") 10 | 11 | 12 | def cube(self): 13 | print(f"the value of {self.number} is {self.number**3}") 14 | 15 | @staticmethod 16 | def greet(): 17 | print("hello welcome to the best calculator") 18 | 19 | a = Calculator(3) 20 | a.greet() 21 | -------------------------------------------------------------------------------- /104_pr05ch10.py: -------------------------------------------------------------------------------- 1 | class Train: 2 | def __init__(self, name, fair, seats): 3 | self.name = name 4 | self.fair = fair 5 | self.seats = seats 6 | 7 | def getStatus(self): 8 | print(f"the name of train is {self.name}.") 9 | print(f"the fair of train is {self.fair}.") 10 | print(f"the seats of train is {self.seats}.") 11 | 12 | def fairInfo(self): 13 | print(f"the price of train ticket is RS- {self.fair}.") 14 | 15 | def bookTicket(self): 16 | if(self.seats)>0: 17 | print(f"your ticket has been booked and \n your seat no is - {self.seats}") 18 | self.seats = self.seats - 1 19 | else: 20 | print("no seats. kindly book in tatkal.") 21 | 22 | def cancelTicket(self,): 23 | pass 24 | 25 | intercity = Train("intercity", 90, 300) 26 | intercity.getStatus() 27 | intercity.fairInfo() 28 | 29 | # booking tickets. 30 | intercity.bookTicket() 31 | intercity.getStatus() 32 | -------------------------------------------------------------------------------- /105_pr06ch10.py: -------------------------------------------------------------------------------- 1 | from unicodedata import name 2 | 3 | 4 | class Sample: 5 | a = "harry" 6 | def __init__(RAJU, name): #overwrite raju in place of self. 7 | RAJU.name = name 8 | 9 | obj = Sample("harry") 10 | print(obj.name) 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /106_Single_inheritence.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "google" 3 | 4 | def showdetails(self): 5 | print("this is an employee") 6 | 7 | class Programmer(Employee): 8 | language = "python" 9 | company = "MASA" 10 | def getName(self): 11 | print(f"the language is {self.language}") 12 | 13 | def showdetails(self): 14 | print("this is an programmer") 15 | 16 | e = Employee() 17 | e.showdetails() 18 | p = Programmer 19 | p.showdetails 20 | print(p.company) -------------------------------------------------------------------------------- /107_ multiple_inheritance.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "visa" 3 | eCode = 120 4 | 5 | class Freelancer: 6 | company = "fiverr" 7 | level = 0 8 | 9 | def upgradeLevel(self): 10 | self.level = self.level + 1 11 | 12 | class Programmer(Freelancer,Employee): 13 | name = "rohit" 14 | 15 | p = Programmer() 16 | p.upgradeLevel() 17 | print(p.company) 18 | -------------------------------------------------------------------------------- /108_multi_level_inheritance.py: -------------------------------------------------------------------------------- 1 | class person: 2 | country = "india" 3 | def takeBreath(self): 4 | print("i am breathing") 5 | 6 | class Employee: 7 | company = "honda" 8 | 9 | def getSalary(self): 10 | print(f"the salary is {self.Salary}") 11 | 12 | def takeBreath(self): 13 | print("i am employee so i am luckyly breathing") 14 | 15 | class Programmer(Employee,person): 16 | company = "fiverr" 17 | 18 | def getSalary(self): 19 | print("no salary to programmers") 20 | 21 | def takeBreath(self): # if dont have meathod then aquires nearest meathod (from Employee) 22 | print("i am programmer so i am luckyly breathing ++") 23 | 24 | p = person() 25 | p.takeBreath() 26 | e = Employee() 27 | e.takeBreath() 28 | pr = Programmer() 29 | pr.takeBreath() 30 | 31 | print(p.country) 32 | print(pr.country) -------------------------------------------------------------------------------- /109_super_meathod.py: -------------------------------------------------------------------------------- 1 | class person: 2 | country = "india" 3 | 4 | def __init__(self): 5 | print("initializing person...\n") 6 | 7 | def takeBreath(self): 8 | print("i am breathing") 9 | 10 | class Employee(person): 11 | company = "honda" 12 | 13 | def __init__(self): 14 | super().__init__() 15 | print("initializing employee...\n") 16 | 17 | def getSalary(self): 18 | print(f"the salary is {self.Salary}") 19 | 20 | def takeBreath(self): 21 | super().takeBreath() 22 | print("i am employee so i am luckyly breathing") 23 | 24 | class Programmer(Employee,person): 25 | company = "fiverr" 26 | 27 | def __init__(self): 28 | super().__init__() 29 | print("initializing programmer...\n") 30 | 31 | def getSalary(self): 32 | print("no salary to programmers") 33 | 34 | def takeBreath(self): # if dont have meathod then aquires nearest meathod (from Employee) 35 | super().takeBreath() 36 | print("i am programmer so i am luckyly breathing ++") 37 | 38 | p = person() 39 | # p.takeBreath() 40 | 41 | e = Employee() 42 | # e.takeBreath() 43 | 44 | pr = Programmer() 45 | # pr.takeBreath() 46 | 47 | -------------------------------------------------------------------------------- /10_RemainderCalculator.py: -------------------------------------------------------------------------------- 1 | # remainder calculator 2 | 3 | a=6756 4 | b=15 5 | 6 | print("The remainder when a is divided by b is ", a%b) -------------------------------------------------------------------------------- /110_class_meathods.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "camel" 3 | salary = 100 4 | lacation = 'delhi' 5 | 6 | def changeSalary(self, sal): 7 | self.__class__.salary = sal 8 | # or 9 | @classmethod 10 | def changeSalary(cls, sal): 11 | cls.salary = sal 12 | 13 | e = Employee() 14 | print(e.salary) 15 | e.changeSalary(400) 16 | print(e.salary) 17 | print(Employee.salary) 18 | -------------------------------------------------------------------------------- /111_property_decorator.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | company = "bharat gas" 3 | salary = 4500 4 | bonus = 500 5 | # totalSalary = 5000 6 | # or 7 | @property 8 | def totalSalary(self): 9 | return self.salary + self.bonus 10 | 11 | @totalSalary.setter 12 | def totalSalary(self,val): 13 | self.bonus = val - self.salary 14 | 15 | e = Employee() 16 | e.totalSalary = 5800 17 | print(e.totalSalary) 18 | print(e.bonus) 19 | 20 | -------------------------------------------------------------------------------- /112_operator_overloading.py: -------------------------------------------------------------------------------- 1 | class Number: 2 | def __init__(self, num): 3 | self.num = num 4 | 5 | def __add__(self, num2): 6 | print("lets add") 7 | return self.num + num2.num 8 | 9 | def __mul__(self, num2): 10 | print("lets multiply") 11 | return self.num * num2.num 12 | 13 | n1 = Number(4) 14 | n2 = Number(6) 15 | sum = n1 + n2 16 | mul = n1 * n2 17 | print(sum) 18 | print(mul) -------------------------------------------------------------------------------- /113_OtherDunderMeathods.py: -------------------------------------------------------------------------------- 1 | # Other Dunder Meathods 2 | class Number: 3 | def __init__(self, num): 4 | self.num = num 5 | 6 | def __add__(self, num2): 7 | print("lets add") 8 | return self.num + num2.num 9 | 10 | def __mul__(self, num2): 11 | print("lets multiply") 12 | return self.num * num2.num 13 | 14 | def __str__(self): 15 | return f"decimal number :\n {self.num} " 16 | 17 | def __len__(self): 18 | print("the len is :") 19 | return 1 20 | 21 | n = Number(9) 22 | print(n) 23 | print(len(n)) -------------------------------------------------------------------------------- /114_pr01ch11.py: -------------------------------------------------------------------------------- 1 | class C2dVec: 2 | def __init__(self,i,j): 3 | self.icap = i 4 | self.jcap = j 5 | 6 | def __str__(self): 7 | return f"{self.icap}i + {self.jcap}j" 8 | 9 | class C3dVec(C2dVec): 10 | def __init__(self,i,j,k): 11 | super().__init__(i,j) 12 | self.kcap = k 13 | 14 | def __str__(self): 15 | return f"{self.icap}i + {self.jcap}j + {self.kcap}k" 16 | 17 | v2d = C2dVec(1,3) 18 | v3d = C3dVec(1,3,7) 19 | print(v2d) 20 | print(v3d) 21 | -------------------------------------------------------------------------------- /115_pr02ch11.py: -------------------------------------------------------------------------------- 1 | class Animals: 2 | animalType = "mamal" 3 | 4 | class Pets: 5 | color = "white" 6 | 7 | class Dog: 8 | @staticmethod 9 | def bark(): 10 | print("bow bow") 11 | 12 | d = Dog() 13 | d.bark() 14 | -------------------------------------------------------------------------------- /116_pr03ch11.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | salary = 1000 3 | increment = 1.5 4 | 5 | @property 6 | def salaryAfterIncrement(self): 7 | return self.salary*self.increment 8 | 9 | @salaryAfterIncrement.setter 10 | def salaryAfterIncrement(self,sai): 11 | self.increment = sai/self.salary 12 | 13 | e = Employee() 14 | print(e.salaryAfterIncrement) 15 | print(e.increment) 16 | e.salaryAfterIncrement = 2000 17 | print(e.salaryAfterIncrement) 18 | print(e.increment) -------------------------------------------------------------------------------- /117_pr04ch11.py: -------------------------------------------------------------------------------- 1 | class Complex: 2 | def __init__(self,r,i): 3 | self.real = r 4 | self.imaginary = i 5 | 6 | def __add__(self,c): 7 | return Complex(self.real + c.real, self.imaginary + c.imaginary) 8 | 9 | 10 | def __mul__(self,c): 11 | mulReal = self.real*c.real - self.imaginary*c.imaginary 12 | mulImg = self.real*c.imaginary + self.imaginary*c.real 13 | return Complex(mulReal, mulImg) 14 | 15 | def __str__(self): 16 | if self.imaginary<0: 17 | return f"{self.real} - {self.imaginary}i" 18 | else: 19 | return f"{self.real} + {self.imaginary}i" 20 | 21 | c1 = Complex(3,2) 22 | c2 = Complex(1,7) 23 | print(c1+c2) 24 | print(c1*c2) 25 | -------------------------------------------------------------------------------- /118_pro5ch11.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, vec): 3 | self.vec = vec 4 | 5 | def __str__(self): 6 | str1 = "" 7 | index = 0 8 | for i in self.vec : 9 | str1 += f" {i}a{index} + " 10 | index +=1 11 | return str1[:-1] 12 | 13 | def __add__(self,vec2): 14 | newList = [] 15 | for i in range(len(self.vec)): 16 | newList.append(self.vec[i] + vec2.vec[i]) 17 | return Vector(newList) 18 | 19 | def __mul__(self,vec2): 20 | sum = 0 21 | for i in range(len(self.vec)): 22 | sum += self.vec[i] * vec2.vec[i] 23 | return sum 24 | 25 | v1 = Vector([1, 4]) 26 | v2 = Vector([1, 6]) 27 | print(v1 + v2) 28 | print(v1 * v2) -------------------------------------------------------------------------------- /119_pr06ch11.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, vec): 3 | self.vec = vec 4 | 5 | def __str__(self): 6 | return f"{self.vec[0]}i + {self.vec[1]}j + {self.vec[2]}k" 7 | 8 | v1 = Vector([1, 4, 6]) 9 | v2 = Vector([1, 6, 9]) 10 | print(v1) 11 | print(v2) -------------------------------------------------------------------------------- /11_AvgCalculator.py: -------------------------------------------------------------------------------- 1 | # AVERAGE CALCULATOR 2 | 3 | a=input("Enter first number") 4 | b=input("Enter second number") 5 | 6 | a=int(a) 7 | b=int(b) 8 | 9 | avg=(a+b)/2 10 | 11 | print("The average of a and b is ", avg) -------------------------------------------------------------------------------- /120_pr07ch11.py: -------------------------------------------------------------------------------- 1 | class Vector: 2 | def __init__(self, vec): 3 | self.vec = vec 4 | 5 | def __str__(self): 6 | str1 = "" 7 | index = 0 8 | for i in self.vec : 9 | str1 += f" {i}a{index} + " 10 | index +=1 11 | return str1[:-1] 12 | 13 | def __add__(self,vec2): 14 | newList = [] 15 | for i in range(len(self.vec)): 16 | newList.append(self.vec[i] + vec2.vec[i]) 17 | return Vector(newList) 18 | 19 | def __mul__(self,vec2): 20 | sum = 0 21 | for i in range(len(self.vec)): 22 | sum += self.vec[i] * vec2.vec[i] 23 | return sum 24 | 25 | def __len__(self): 26 | return len(self.vec) 27 | 28 | v1 = Vector([1, 4, 6]) 29 | v2 = Vector([1, 6]) 30 | print(len(v1)) 31 | print(len(v2)) -------------------------------------------------------------------------------- /121_GuessTheNumber_Game.py: -------------------------------------------------------------------------------- 1 | # Guess the number game 2 | import random 3 | randNumber = random.randint(1,100) 4 | # print(randNumber) 5 | userGuess = None 6 | guesses = 0 7 | 8 | while(userGuess != randNumber): 9 | userGuess = int(input("Enter your Guess:\n")) 10 | guesses +=1 11 | if(userGuess == randNumber): 12 | print("you guessed it right!") 13 | else: 14 | if(userGuess>randNumber): 15 | print("you guessed it wrong! Enter a smaller number") 16 | else: 17 | print("you guessed it wrong! Enter a larger number") 18 | 19 | print(f"You guessed the number in -: \n {guesses} guesses") 20 | 21 | with open("122_highscore.txt", "r") as f: 22 | highscore = int(f.read()) # first save int literal in file. 23 | 24 | if(guesses, 2 | greetings from abc house 3 | Im happpy to tell you about your selection 4 | you are selected! 5 | Date: <|Date|> 6 | Have a great day. 7 | thanks and regards. 8 | ''' 9 | name = input("enter your name\n") 10 | Date = input("enter Date\n") 11 | letter=letter.replace("<|Name|", name) 12 | letter=letter.replace("<|Date|", Date) 13 | print(letter) 14 | 15 | 16 | -------------------------------------------------------------------------------- /19_pr_03ch3.py: -------------------------------------------------------------------------------- 1 | st = "this is a string with double spaces" 2 | # to find the first double space 3 | doubleSpaces=st.find(" ") 4 | print(doubleSpaces) 5 | -------------------------------------------------------------------------------- /20_pr_04ch3.py: -------------------------------------------------------------------------------- 1 | st = "this is a string with double spaces" 2 | # to find the first double space 3 | doubleSpaces=st.replace(" ","great") 4 | print(doubleSpaces) -------------------------------------------------------------------------------- /21_pr_05ch3.py: -------------------------------------------------------------------------------- 1 | letter = "dear harry, this python course is nice ! thanks!" 2 | print(letter) 3 | formatted_letter = "dear harry,\n this python course is\t nice !\n thanks!" 4 | print(formatted_letter) 5 | -------------------------------------------------------------------------------- /22_List=[ ].py: -------------------------------------------------------------------------------- 1 | # LIST:- 2 | # create a list using[] 3 | a = [12,2,3,46,15,6] 4 | 5 | # print the list using print() function 6 | print(a) 7 | print(a[0]) 8 | 9 | # access index using a[0], a[2] and change the value of list 10 | a[0] = 87 11 | print(a[0]) 12 | 13 | # we can create a list with item of different types 14 | c = [45 ,"harry", False, 6.9] 15 | print(c) 16 | 17 | # list slicing 18 | friends = ["harry","tom","rohan","sam","divia","45"] 19 | print(friends[0:4]) 20 | print(friends[-4:-2]) 21 | 22 | # list meathods 23 | l1 = [1,8,7,21,15] 24 | print(l1) 25 | 26 | # l1.sort() .sorts the list 27 | # l1.reverse() .reverse the list 28 | # l1.append(45) .adds to the end of the list 29 | # l1.insert(0,544) .inserts 544 at index 2 30 | # l1.pop(2) .removes element at index 2 31 | # l1.remove(21) .removes 21 from the list 32 | # print(l1) 33 | -------------------------------------------------------------------------------- /23_Tuple( ).py: -------------------------------------------------------------------------------- 1 | # TUPLE:- 2 | # creating a tuple using () 3 | t = (1,2,4,5) 4 | 5 | # wrong tuple t1=(1) 6 | t1=(1,) 7 | print(t1) 8 | 9 | # printing the elements of the tuple 10 | print(t[0]) 11 | 12 | # cannot update the values of tuple 13 | # t[0]=34 (throws syntax error) -------------------------------------------------------------------------------- /24_TupleMethods.py: -------------------------------------------------------------------------------- 1 | # Tuple meathods 2 | 3 | t = (1,2,4,5,4,1,2,1,1) 4 | 5 | print(t.count(1)) 6 | print(t.index(3)) -------------------------------------------------------------------------------- /25_pr_Fruits.py: -------------------------------------------------------------------------------- 1 | f1 = input("enter fruit number 1") 2 | f2 = input("enter fruit number 2") 3 | f3 = input("enter fruit number 3") 4 | f4 = input("enter fruit number 4") 5 | f5 = input("enter fruit number 5") 6 | f6 = input("enter fruit number 6") 7 | f7 = input("enter fruit number 7") 8 | 9 | myFruitList = [f1, f2, f3, f4, f5, f6, f7] 10 | 11 | print(myFruitList) 12 | -------------------------------------------------------------------------------- /26_pr_Marks.py: -------------------------------------------------------------------------------- 1 | m1 = int(input("enter marks for student 1")) 2 | m2 = int(input("enter marks for student 2")) 3 | m3 = int(input("enter marks for student 3")) 4 | m4 = int(input("enter marks for student 4")) 5 | m5 = int(input("enter marks for student 5")) 6 | m6 = int(input("enter marks for student 6")) 7 | m7 = int(input("enter marks for student 7")) 8 | 9 | mylist = [m1,m2,m3,m4,m5,m6,m7] 10 | mylist.sort() 11 | print(mylist) 12 | -------------------------------------------------------------------------------- /27_pr_Sum_of_a_List.py: -------------------------------------------------------------------------------- 1 | a= [2,4,56,7] 2 | # two different ways 3 | 4 | print(a[0]+a[1]+a[2]+a[3]+a[4]) 5 | 6 | print(sum(a)) 7 | -------------------------------------------------------------------------------- /28_Dictionary{ }.py: -------------------------------------------------------------------------------- 1 | from calendar import c 2 | 3 | 4 | myDict = { 5 | "Fast": "In a quick Manner", 6 | "Harry": "A Coder", 7 | "marks": [1,3,4], 8 | "anotherdict":{'harry':'Player'} # NESTED DICTIONARY 9 | } 10 | print(myDict['marks']) 11 | print(myDict['Fast']) 12 | myDict['marks']=[45,56,67] 13 | print(myDict['marks']) 14 | print(myDict['anotherdict']['harry']) 15 | 16 | -------------------------------------------------------------------------------- /29_DictionaryMethods.py: -------------------------------------------------------------------------------- 1 | # DICTIONARY METHODS :- 2 | 3 | myDict = { 4 | "fast": "In a quick Manner", 5 | "harry": "A Coder", 6 | "marks": [1,3,4], 7 | "anotherdict":{'harry':'Player'}, # NESTED DICTIONARY 8 | 1:2 9 | } 10 | # dictionary meathods 11 | print(myDict.keys()) 12 | print(type(myDict.keys()))# type is dict_keys 13 | print(list(myDict.keys()))# print the keys of the dictionary 14 | print(myDict.values())# prints values 15 | print(myDict.items())# prints keys and values 16 | 17 | print(myDict) 18 | updateDict ={ 19 | "lovish": "friend", 20 | "shubham":"friend", 21 | "harry": "A teacher", 22 | 23 | } 24 | myDict.update(updateDict) # updated dictionary by adding key value pairs 25 | print(myDict) 26 | # same result 27 | print(myDict.get("harry"))# returns none 28 | print(myDict["harry"])# throws an error need to write correct keys. 29 | -------------------------------------------------------------------------------- /30_Sets{ }.py: -------------------------------------------------------------------------------- 1 | # Set is collection of non repeatating elements. 2 | # bracket of sets and dictionary are same. Dictionary has a different syntax. An empty set has same bracket as a Tuple. 3 | 4 | a = {1,3,4,5,1} 5 | print(type(a)) 6 | print(a) 7 | # anywhere in coding if u get unique it means set -------------------------------------------------------------------------------- /31_EmptySet( ).py: -------------------------------------------------------------------------------- 1 | # the system will create an empty Dictionary not an empty Set. 2 | a = {} 3 | print(type(a)) 4 | 5 | # this system creates an empty set 6 | b = set() 7 | print(type(b)) 8 | b.add(4) 9 | b.add(5) 10 | b.add(5) 11 | b.add(5) 12 | 13 | 14 | print(b) -------------------------------------------------------------------------------- /32_SetsMeathods.py: -------------------------------------------------------------------------------- 1 | # Sets Meathods:- 2 | 3 | b = set() 4 | # add values to null set 5 | b.add(4) 6 | b.add(5) 7 | # b.add([4,5,6]) #list cant be added as its not hashable contents can be changed 8 | b.add((4,5,6)) #tupple can be addded 9 | # b.add({4:5}) #dictionary cant be added as its not hashable contents can be changed 10 | 11 | print(b) 12 | 13 | print(len(b)) # prints the length of this set 14 | b.remove(5) 15 | # b.remove(15) throws an error as 15 is not in set 16 | 17 | print(b) 18 | -------------------------------------------------------------------------------- /33_pr_ch5.py: -------------------------------------------------------------------------------- 1 | myDict = { 2 | "nwjw":"oiknwsj", 3 | "hjsu":"kimkwu", 4 | "ksnw":"osjjw" 5 | } 6 | print("optins are", myDict.keys()) 7 | a = input("enter the hindi word\n") 8 | # print("the meaning of your word is:", myDict[a]) throws an error 9 | print("the meaning of your word is:", myDict.get(a)) # returns null value if key is not present in dictionary. 10 | 11 | -------------------------------------------------------------------------------- /34_pr_ch5.py: -------------------------------------------------------------------------------- 1 | num1 = int(input("enter number 1\n")) 2 | num2 = int(input("enter number 2\n")) 3 | num3 = int(input("enter number 3\n")) 4 | num4 = int(input("enter number 4\n")) 5 | num5 = int(input("enter number 5\n")) 6 | num6 = int(input("enter number 6\n")) 7 | num7 = int(input("enter number 7\n")) 8 | num8 = int(input("enter number 8\n")) 9 | 10 | s = {num1,num2,num3,num4,num5,num6,num7,num8} 11 | print(s) -------------------------------------------------------------------------------- /35_pr_ch5.py: -------------------------------------------------------------------------------- 1 | s = {18,"18","18",18.0} 2 | print(s) 3 | print(len(s)) # [ gives length 2 counts 18 and 18.0 as same, 4 | # but prints it differently as integer ans floating point] 5 | 6 | a = () #truple 7 | b = {} #dictionary 8 | c = [] #list 9 | d = set() # empty set 10 | e = {8} 11 | 12 | print(type(a)) 13 | print(type(b)) 14 | print(type(c)) 15 | print(type(d)) 16 | print(type(e)) 17 | -------------------------------------------------------------------------------- /36_pr06_ch5.py: -------------------------------------------------------------------------------- 1 | favlang = {} 2 | a = input("enter your favorite language shubham\n") 3 | b = input("enter your favorite language ankit\n") 4 | c = input("enter your favorite language sonali\n") 5 | d = input("enter your favorite language ankita\n") 6 | 7 | favlang['shubham'] = a 8 | favlang['ankit'] = b 9 | favlang['sonali'] = c 10 | favlang['ankita'] = d 11 | 12 | print(favlang) 13 | -------------------------------------------------------------------------------- /37_Conditionals.py: -------------------------------------------------------------------------------- 1 | # CONDITIONALS:- 2 | 3 | a = int(input("enter your number")) 4 | 5 | # 1. If else ladder 6 | 7 | 8 | # if(a<3): 9 | # print("the value of a less than 3") 10 | # elif(a<7): 11 | # print("the value of a is less than 7") 12 | # elif(a<13): 13 | # print("the value of a is less than 13") 14 | # elif(a<17): 15 | # print("the value of a is less than 17") 16 | # else: 17 | # print("the value of a is greater than 3 7 13 17") 18 | 19 | 20 | # 2. Multiple if statements 21 | 22 | 23 | if(a<3): 24 | print("the value of a less than 3") 25 | if(a<7): 26 | print("the value of a is less than 7") 27 | if(a<13): 28 | print("the value of a is less than 13") 29 | if(a<17): 30 | print("the value of a is less than 17") 31 | else: 32 | print("the value of a is greater than 3 7 13 17") -------------------------------------------------------------------------------- /38_NotesQuiz.py: -------------------------------------------------------------------------------- 1 | a = int(input("enter your age : ")) 2 | 3 | 4 | if(a>=18): 5 | print("yes.you are welcomes in") 6 | else: 7 | print("sorry.you are under aged") -------------------------------------------------------------------------------- /39_in_and_is.py: -------------------------------------------------------------------------------- 1 | a = None 2 | 3 | if (a is None):# "is" is used in place of == operator 4 | print("yes") 5 | 6 | 7 | 8 | else: 9 | print("no") 10 | 11 | a = [45,56,6] 12 | print(27 in a) # gives false 13 | -------------------------------------------------------------------------------- /40_ElseOptional.py: -------------------------------------------------------------------------------- 1 | a = int(input("enter your number")) 2 | 3 | # 1. If else ladder 4 | 5 | 6 | if(a<3): 7 | print("the value of a less than 3") 8 | elif(a<7): 9 | print("the value of a is less than 7") 10 | elif(a<13): 11 | print("the value of a is less than 13") 12 | elif(a<17): 13 | print("the value of a is less than 17") 14 | 15 | # Hence we conclude that else is an optional conditional. -------------------------------------------------------------------------------- /41_pr01_ch6.py: -------------------------------------------------------------------------------- 1 | num1 = int(input("enter number 1: ")) 2 | num2 = int(input("enter number 2: ")) 3 | num3 = int(input("enter number 3: ")) 4 | num4 = int(input("enter number 4: ")) 5 | 6 | if(num1>num4): 7 | f1 =num1 8 | else: 9 | f1=num4 10 | 11 | 12 | if(num2>num3): 13 | f2 =num2 14 | else: 15 | f2=num3 16 | 17 | 18 | if(f1>f2): 19 | print(str(f1) + "is greatest") 20 | else: 21 | print(str(f2) + "is greatest") 22 | 23 | -------------------------------------------------------------------------------- /42_pr02_ch6.py: -------------------------------------------------------------------------------- 1 | sub1 = int(input("Enter first subject marks\n")) 2 | sub2 = int(input("Enter second subject marks\n")) 3 | sub3 = int(input("Enter third subject marks\n")) 4 | 5 | if(sub1<33 or sub2<33 or sub3<33): 6 | print("You are fail because you have less than 33% in one of the subjects") 7 | elif(sub1+sub2+sub3)/3 < 40: 8 | print("You are fail due to total percentage less than 40") 9 | else: 10 | print("Congatulations! You passed the exam") -------------------------------------------------------------------------------- /43_pr03_ch6.py: -------------------------------------------------------------------------------- 1 | text = input("enter the text") 2 | spam = False 3 | 4 | if("make a lot of money" in text): 5 | spam = True 6 | elif("buy now" in text): 7 | spam = True 8 | elif("click this" in text): 9 | spam = True 10 | elif("subscribe this" in text): 11 | spam = True 12 | else: 13 | spam = False 14 | 15 | 16 | if(spam): 17 | print("the text is spam") 18 | else: 19 | print("text is not a spam") 20 | -------------------------------------------------------------------------------- /44_pr05_ch6.py: -------------------------------------------------------------------------------- 1 | names = ["harry", "shubham","rohit","aditi","shipra"] 2 | name = input("enter the name to check") 3 | 4 | if name in names: 5 | print("your name is present in the list") 6 | else: 7 | print("your name is not present in the list") -------------------------------------------------------------------------------- /45_pr06_ch6.py: -------------------------------------------------------------------------------- 1 | marks = int(input("enter your marks\n")) 2 | 3 | if marks>=90: 4 | grade="Ex" 5 | elif marks>=80: 6 | grade="A" 7 | elif marks>=70: 8 | grade="B" 9 | elif marks>=60: 10 | grade="C" 11 | elif marks>=50: 12 | grade="D" 13 | else: 14 | grade="F" 15 | 16 | print("your grade is :" + grade) 17 | -------------------------------------------------------------------------------- /46_WhileLoop.py: -------------------------------------------------------------------------------- 1 | # WHILE LOOP:- 2 | 3 | i = 4 4 | while i<10: 5 | print("yes" + str(i)) 6 | i = i+2 7 | 8 | print("done") 9 | -------------------------------------------------------------------------------- /47_print(Num)-WhileLoop.py: -------------------------------------------------------------------------------- 1 | i = 0 2 | 3 | while i<=50: 4 | print("Printed"+ str(i)) 5 | i = i + 1 6 | # print("done") print statement start from column 1 to ensure its not from ladder 7 | print("done") 8 | -------------------------------------------------------------------------------- /48_Loops_Ex.py: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i<5 : 3 | print("good for" + str(i)) 4 | i = i+1 -------------------------------------------------------------------------------- /49_ListLoops.py: -------------------------------------------------------------------------------- 1 | fruits = ['Banana','watermelon','grapes','mango'] 2 | i = 0 3 | while i0 : 12 | pass 13 | 14 | while i>6: 15 | pass 16 | 17 | print("raju is a good boy") 18 | -------------------------------------------------------------------------------- /56_pr_01ch7.py: -------------------------------------------------------------------------------- 1 | num = int(input("enter the number\n")) 2 | for i in range(1,11): 3 | # print(str(num) + "x" + str(i) + "=" + str(i*num)) 4 | print(f"{num}x{i}={num*i}") 5 | 6 | -------------------------------------------------------------------------------- /57_pr02ch7.py: -------------------------------------------------------------------------------- 1 | l1 = ["harry","sohan","sachin","rahul"] 2 | 3 | for name in l1 : 4 | if name.startswith("s") : 5 | print("hello" + name) 6 | -------------------------------------------------------------------------------- /58_pr04ch7.py: -------------------------------------------------------------------------------- 1 | num = int(input("enter the number:\n")) 2 | prime = True 3 | for i in range(2,num): 4 | if(num%i == 0) : 5 | prime = False 6 | break 7 | if prime : 8 | print("this number is prime") 9 | else: 10 | print("this number is not a prime") 11 | 12 | -------------------------------------------------------------------------------- /59_pr06ch7.py: -------------------------------------------------------------------------------- 1 | num = int(input("enter the number:\n")) 2 | factorial = 1 3 | for i in range(1,num+1): 4 | factorial = factorial * i 5 | print(f"the facorial of this number is {factorial}") -------------------------------------------------------------------------------- /60_pr07_StarPattern.py: -------------------------------------------------------------------------------- 1 | n = 7 2 | for i in range(n): 3 | print(" " * (n-i-1), end = "") 4 | print("*" * (2*i+1), end = "") 5 | print(" " * (n-i-1)) 6 | -------------------------------------------------------------------------------- /61_pr08ch7_StarPattern.py: -------------------------------------------------------------------------------- 1 | n = int(input("enter the number")) 2 | 3 | for i in range(n): 4 | print("*" * (i+1)) 5 | -------------------------------------------------------------------------------- /62_Functions.py: -------------------------------------------------------------------------------- 1 | # FUNCTIONS:- 2 | 3 | # marks1 = [45, 78, 86, 77] 4 | # percentage1 = ((marks1[0]+marks1[1]+marks1[2]+marks1[3])/400)*100 5 | 6 | 7 | # marks2 = [23, 54, 89, 65] 8 | # percentage2 = (sum(marks2)/400)*100 9 | 10 | # print(percentage1,percentage2) 11 | def percent(marks): 12 | p = ((marks[0] + marks[1] + marks[2]+ marks[3])/400 )*100 13 | return p 14 | 15 | marks1 = [45, 78, 86, 77] 16 | percentage1 = percent(marks1) 17 | 18 | marks2 = [75, 98, 88, 78] 19 | percentage2 = percent(marks2) 20 | print(percentage1, percentage2) -------------------------------------------------------------------------------- /62_QuickQuiz.py: -------------------------------------------------------------------------------- 1 | def greet(name): 2 | print("good day," + name) 3 | 4 | def mysum(num1,num2): 5 | return num1+num2 6 | 7 | greet("raju") 8 | s = mysum(7,8) 9 | print(s) 10 | -------------------------------------------------------------------------------- /63_DefaultArguements.py: -------------------------------------------------------------------------------- 1 | def greet(name ="stranger"): # Stranger in functioal line is a default arguement. 2 | print("good day," + name) 3 | 4 | 5 | greet("raju") 6 | greet() 7 | -------------------------------------------------------------------------------- /64_Recursion.py: -------------------------------------------------------------------------------- 1 | # n = 4 2 | # product = 1 3 | # for i in range(n): 4 | # product = product * (i+1) 5 | # print(product) 6 | 7 | def factorial_iter(n): 8 | product = 1 9 | for i in range(n): 10 | product = product * (i+1) 11 | return product 12 | 13 | f = factorial_iter(7) 14 | print(f) 15 | 16 | # Printing factorial of a number using recursive function. 17 | def factorial_recursive(n): 18 | if n == 1 or n==0 : 19 | return 1 20 | return n* factorial_recursive(n-1) 21 | 22 | F = factorial_recursive(5) 23 | print(F) 24 | -------------------------------------------------------------------------------- /65_pr01ch8.py: -------------------------------------------------------------------------------- 1 | # Function to print max of 2 functions. 2 | 3 | def maximum(num1, num2, num3): 4 | if (num1>num2): 5 | if(num1>num3): 6 | return num1 7 | else: 8 | return num3 9 | else: 10 | if (num2>num1): 11 | if(num2>num3): 12 | return num2 13 | else: 14 | return num3 15 | 16 | 17 | m = maximum(3, 8, 9) 18 | print("the max value is :" + str(m)) 19 | -------------------------------------------------------------------------------- /66_pr02ch8.py: -------------------------------------------------------------------------------- 1 | # To convert celcius to farenheit. 2 | 3 | def farh(cel): 4 | return ( cel * (9/5) ) + 32 5 | 6 | c = 100 7 | f = farh(c) 8 | 9 | print("farenheit temp is:" + str(f)) 10 | -------------------------------------------------------------------------------- /67_pr03ch8.py: -------------------------------------------------------------------------------- 1 | # printing with escape sequences 2 | 3 | print("hello", end = " ") 4 | print("how", end = "\n ") 5 | print("are", end = " ") 6 | print("you", end = " ") 7 | -------------------------------------------------------------------------------- /68_pr05ch8_StarTattern.py: -------------------------------------------------------------------------------- 1 | # Printing star in reverse order. 2 | 3 | n = 6 4 | for i in range(n): 5 | print("*"*(n-i)) # prints * n-i times 6 | -------------------------------------------------------------------------------- /69_pr07.py: -------------------------------------------------------------------------------- 1 | # remove_and_split function 2 | 3 | def remove_and_split(string, word): 4 | newstr = string.replace(word, "") 5 | return newstr.strip() 6 | 7 | 8 | this = " harry is a good boy " 9 | print(this) 10 | 11 | n = remove_and_split(this, "harry") 12 | print(n) 13 | 14 | print(this.strip()) 15 | print(this.split()) 16 | 17 | # split segregates words and prints them as a list using ''. 18 | # strip removes blank charectar spaces within the string. -------------------------------------------------------------------------------- /70_snake_water_gun_Game.py: -------------------------------------------------------------------------------- 1 | # SNAKE-WATER-GUN GAME 2 | 3 | import random 4 | randNo = random.randint(1,3) 5 | #print(randNo) 6 | 7 | # Game algorithms. 8 | def game(comp,you): 9 | 10 | 11 | if comp ==you: 12 | return None 13 | 14 | 15 | 16 | elif comp == 's': 17 | if you=='w': 18 | return False 19 | 20 | elif you == 'g': 21 | return True 22 | 23 | 24 | 25 | elif comp == 'w': 26 | if you=='g': 27 | return False 28 | 29 | elif you == 's': 30 | return True 31 | 32 | 33 | 34 | elif comp == 'g': 35 | if you=='s': 36 | return False 37 | 38 | elif you == 'w': 39 | return True 40 | 41 | # Charectar selection for computer. 42 | 43 | if randNo == 1: 44 | comp = 's' 45 | elif randNo == 2: 46 | comp = 'w' 47 | elif randNo == 3: 48 | comp = 'g' 49 | 50 | 51 | # Charectar selection for player. 52 | 53 | you = input("Your Turn : Snake(s) , Water(w) or Gun(g) ?\n ") 54 | 55 | a = game(comp,you) 56 | 57 | print(f"computer chosed {comp}") 58 | print(f"you chosed {you}") 59 | 60 | if a == None: 61 | print("MATCH TIED , REMATCH? ") 62 | 63 | elif a: 64 | print("YOU WIN!") 65 | 66 | else : 67 | print("YOU LOSE , REMATCH? ") 68 | -------------------------------------------------------------------------------- /71_Files.py: -------------------------------------------------------------------------------- 1 | # use open function to read the content of a file 2 | 3 | # f = open('sample.txt', 'r') 4 | f = open('72_sample.txt') #by default the code is r 5 | 6 | # data = f.read() 7 | data = f.read(11)# reads only 11 charectars 8 | 9 | print(data) 10 | f.close() -------------------------------------------------------------------------------- /72_Sample.txt: -------------------------------------------------------------------------------- 1 | $$$$$$ 2 | t$$$$$$s $$$$$$ $$$$$$ 3 | $$$$$$ $$$$$$ $$$$$$ 4 | $$$$$$ $$$$$$ a programer. 5 | $$$$$$ $$$$$$ a $$$$$$ $$$$$$. 6 | $$$$$$ -------------------------------------------------------------------------------- /73_Readline.py: -------------------------------------------------------------------------------- 1 | f = open('72_sample.txt', 'r') 2 | # read first line 3 | data = f.readline() 4 | print(data) 5 | 6 | # read second line 7 | data = f.readline() 8 | print(data) 9 | 10 | # read third line 11 | data = f.readline() 12 | print(data) 13 | 14 | # read fourth line 15 | data = f.readline() 16 | print(data) 17 | 18 | f.close() -------------------------------------------------------------------------------- /74_Write.py: -------------------------------------------------------------------------------- 1 | # f = open('75_another.txt','w') # to write in file,content gets erased and is written from starting. 2 | f = open('75_another.txt','a') # to append file,can be run multiple times 3 | 4 | f.write("This text is written to the file.\n") 5 | f.write("This text is written to the file.\n") 6 | f.write("This text is written to the file.\n") 7 | f.write("This text is written to the file.\n") 8 | 9 | f.close() 10 | 11 | -------------------------------------------------------------------------------- /75_Another.txt: -------------------------------------------------------------------------------- 1 | hiThis text is written to the file. 2 | This text is written to the file. 3 | This text is written to the file. 4 | This text is written to the file. 5 | -------------------------------------------------------------------------------- /76_with_Statement.py: -------------------------------------------------------------------------------- 1 | # no need to close file with the with statement. 2 | with open('75_another.txt', "r") as f: 3 | # if by chance u open file in w or a mode the content of the file 4 | # gets deleted and non readable error is shown. 5 | a = f.read() 6 | print(a) -------------------------------------------------------------------------------- /77_pr01ch9.py: -------------------------------------------------------------------------------- 1 | f = open('78_poems.txt') 2 | t = f.read() 3 | if 'twinkle'in t: 4 | print("twinkle is present") 5 | else: 6 | print("twinkle is not present") 7 | 8 | f.close() -------------------------------------------------------------------------------- /78_Poems.txt: -------------------------------------------------------------------------------- 1 | twinkle twinkle star 2 | twinkle twinkle star 3 | how i wonder what u r! -------------------------------------------------------------------------------- /79_pr02ch9_code.py: -------------------------------------------------------------------------------- 1 | def game(): 2 | return 66888 3 | 4 | 5 | score = game() 6 | with open("80_highscore.txt") as f : 7 | highscorestr = f.read() 8 | 9 | 10 | if highscorestr =='': 11 | with open("80_highscore.txt","w") as f : 12 | f.write(str(score)) 13 | 14 | 15 | elif int(highscorestr)