INDEX S.No DATE TITLE PAGE NO SIGNATURE 1. Editing and executing Programs involving Flow Controls 2. Editing and executing Programs involving Functions. 3. Program in String Manipulations 4. . Creating and manipulating a Tuple 5. Creating and manipulating a List 6. Creating and manipulating a Dictionary 7. Object Creation and Usage 8. Program involving Inheritance 9. Program involving Overloading 10. Reading and Writing with Text Files and Binary Files 11. Combining and Merging Data Sets 12. Program involving Regular Expressions 13. Data Aggregation and GroupWise Operations 1. EDITING AND EXECUTING FLOW CONTROL IF STATEMENT : x=int(input("Enter mark:")) if(90<=x<=100): print("Execellent") elif(75<=x<=90): print("Outstanding") elif(50<=x<=75): print("A+") elif(35<=x<=50): print("A") else: print( "Fail") FOR LOOP STATEMENT : for n in range(1,11): square=n**2 print("Square number",square) WHILE LOOP STATEMENT : num=2 while num<=50: print(num) num+=2 BREAK STATEMENT : for n in range(5): if n==2: break print(n) CONTINUE STATEMENT : for n in range(5): if n==2: continue print(n) PASS STATEMENT for n in range(5): if n==2: pass print(n) OUTPUT: 2. EDITING AND EXECUTING PROGRAMS INVOLVING FUNCTIONS def area(l,b): return(l*b) def perimeter(l,b): return(2*(l+b)) l=int(input("Enter Length:")) b=int(input("Enter Breadth:")) print("Area of rectangle:",area(l,b)) print("Perimeter of rectangle:",perimeter(l,b)) OUTPUT : 3. PROGRAMS IN STRING MANIPULATION Sentence="Welcome to Python" word1=Sentence.split() word2=" ".join(Sentence) word3=Sentence.upper() word4=Sentence.lower() word5=Sentence.capitalize() word6=Sentence.find("Python") word7=Sentence.replace("Python","Java") word8=Sentence[:: - 1] word9=Sentence.rstrip() word10=Sentence.lstrip() print(word1) print(word2) print(word3) print(word4) print(word5) print(word6) print(word7) print(word8) print(word9) print(word10) OUTPUT : 4. CREATING AND MANIPULATING A TUPLE tuple4=("python","java","java script",17,7) print(tuple4) print(len(tuple4)) print(type(tuple4)) tuple1=(1,2,3,4,5,6,7) print(tuple1[2]) print(tuple1[ - 1]) print(tuple1[3:5]) print(tuple1[ - 1: - 3]) tuple2=tuple4+tuple1 print(tuple2) list1=list(tuple4) print(list1) list1.append(22) print(list1) tuple3=tuple(list1) print(tuple3) print(tuple1.count(1)) index=tuple4[3] print(index) OUTPUT: 5. CREATING AND MANIPULATING A LIST mylist=[1,2,3,4,5] print("list elements:",mylist) print("length of list:",len(mylist)) print("list type:",type(mylist)) print("Neg Indexing:",mylist[ - 1]) print("Indexing:",mylist[0]) print("Indexing:",mylist[3:5]) t1=mylist+[7,8,9] print("concatination:",t1) tuple1=tuple(mylist) print("Converting into tuple:",tuple1) list1=list(tuple1) list1.append(5) print("appending:",list) print("counting:",list1.count(2)) OUTPUT: 6. CREATING AND MANIPULATING A DICTIONARY data={ "Name":[" Alice","Bob","Charlie"], "Age":[25,30,35], "City":["New york","los angeles","chicago"] } for key,value in data.items(): print(f"{key}:{value}") for key in data: print(key) for value in data.values(): print(value) data["Profession"]=["Engineer","Doctor","Artist"] print(data["Profession"]) data["Age"][1]=31 print(data["Name"],data["Age"],data["Profession"]) print(data["City"]) del data["City"] for key,value in data.items(): print(f"{key}:{value}") print(data["Name"][0]) print(data["Name"][0],data["Age"][0],data["Profession"][0]) OUTPUT: 7. OBJECT CREATION AND USAGE class Car: def __init__(self,brand,model,year): self.brand=brand self.model=model self.year=year def display_info(self): print(f"Car:{self.year}{self.brand}{self.model}") def start_engine(self): print(f"{self.brand}{self.model}'s engine has started.") def stop_engine(self): print(f"{self.brand}{self.model}'s engine has stopped.") car1=Car("Toyota","Corolla",2022) car2=Car("Honda","Civic",2023) car1.display_info() car1.start_engine() car1.stop_engine() car2.display_info() car2.start_engine() car2.stop_engine() OUTPUT: 8. PROGRAM INVOLVING INHERITANCE class Animal: def __init__(self,name): self.name=name def make_sound(self): return "Some generic animal sound" class Dog(Animal): def make_sound(self): return"Bark!" class Cat(Animal): def make_sound(self): return"Meow!" dog=Dog("Buddy") cat=Cat("Whiskers") print(f"{dog.name}says:{dog.make_sound()}") print(f"{cat.name}says:{cat.make_sound()}") OUTPUT : 9 PROGRAM INVOLVING OVERLOADING from multipledispatch import dispatch import numpy as np # Overloaded function for integer inputs @dispatch(int, int) def mean(a, b): return (a + b) / 2 # Overloaded function for list input @dispatch(list) def mean(arr): return sum(arr) / len(arr) # Overloaded function for NumPy array @dispatch(np.ndarray) def mean(arr): return np.mean(arr) # Test cases print("Mean of 3 and 5:", mean(3, 5)) # Calls int, int version print("Mean of [1, 2, 3, 4, 5]:", mean([1, 2, 3, 4, 5])) # Calls list version print("Mean of NumPy array:", mean(np.array([1.5, 2.5, 3.5, 4.5]))) # Calls ndarray version OUTPUT: 10 READING AND WRITING WITH TEXT FILES AND BINARY FILES import numpy as np # ------------------ TEXT FILE OPERATIONS ------------------ # Writing to a text file with open("data.txt", "w") as text_file: text_file.write("Hello, Data Science! \ n") text_file.write("Working with text and binary files. \ n") # Reading from a text file with open("data.txt", "r") as text_file: text_content = text_file.read() print(" ๐ Text File Content: \ n", text_content) # ------------------ BINARY FILE OPERATIONS ------------------ # Example data (NumPy array) data_array = np.array([10, 20, 30, 40, 50]) # Writing to a binary file using NumPy np.save("data.npy", data_array) # Reading from a binary file using NumPy loaded_array = np.load("data.npy") print(" ๐ Binary File (NumPy) Loaded Data:", loaded_array)