Program No.1: Program to Demonstrate usage of basic regular expression. import re str = "The rain in spain" x = re.findall("ai",str) print("Search of string 'ai': ",x) x = re.search("\s" ,str) print("The first white-space character is located in position : ",x.start()) x = re.split("\s",str,1) print("Split the string in the occurrence of first white-space:",x) x = re.sub("\s","9",str) print("Each white-space is replaced with 9 digit: ",x) print("----------------------------------------------") x = re.findall("[a-m]",str) print("The letters in between a to m in the string:",x) x = re.findall("spain$",str) if(x): print("\n", str, ": Yes, this string ends with 'spain' word ") else: print("\n No match ") x = re.findall("^The",str) if(x): print("\n",str,": Yes, this string starts with 'The' word") else: print("\n No match") str1 = "The rain in spain falls mainly in the plain" x = re.findall("aix*",str1) print("\n All ai matching characters:",x) if(x): print("Yes, there is atleast one match") else: print("No match") x = re.findall("al{2}",str1) print("\n The string which contains 'all':",x) if(x): print("Yes, there is atleast one match") else: print("No match") str2 = "That will be 59 dollars" x = re.findall("\d",str2) print("\n Digits in the string:",x) x = re.findall("do...rs",str2) print("\n Dot meta character matches any character:",x) OUTPUT: Search of string 'ai': ['ai', 'ai'] The first white-space character is located in position : 3 Split the string in the occurrence of first white-space: ['The', 'rain in spain'] Each white-space is replaced with 9 digit: The9rain9in9spain ---------------------------------------------- The letters in between a to m in the string: ['h', 'e', 'a', 'i', 'i', 'a', 'i'] The rain in spain : Yes, this string ends with 'spain' word The rain in spain : Yes, this string starts with 'The' word All ai matching characters: ['ai', 'ai', 'ai', 'ai'] Yes, there is atleast one match The string which contains 'all': ['all'] Yes, there is atleast one match Digits in the string: ['5', '9'] Dot meta character matches any character: ['dollars'] Program No.2: Program to Demonstrate use of advanced regular expressions for data validation. import re def validate_password(password): regular_expression = "^(?=.*[a-z])(?=.*[A- Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{6,20}$" pattern = re.compile(regular_expression) valid = re.search(pattern, password) if valid: print("Password is valid.") else: print("Password is invalid.") # main method starts HERE….. list_of_passwords = ['Abc@123', 'abc@123', 'ABC@123', 'Abc@xyz', 'abc123', '12@#$%Abc', 'Ab@1', "AAAAAbbbbbcccccc@#$%123456789"] for i in list_of_passwords: print(i, ":"), validate_password(i) OUTPUT: Abc@123 : Password is valid. abc@123 : Password is invalid. ABC@123 : Password is invalid. Abc@xyz : Password is invalid. abc123 : Password is invalid. 12@#$%Abc : Password is valid. Ab@1 : Password is invalid. AAAAAbbbbbcccccc@#$%123456789 : Password is invalid. Program No.3: Program to Demonstrate use of list. print("PROGRAM FOR BUILT-IN METHODS OF LIST\n") animal=['Cat','Dog','Rabbit'] print("Old list:->",animal) animal.append('Cow') print("Updated list:->",animal) language=['Python','Java','C++','C'] print("Old list:->",language) return_value=language.pop(3) print("Updated List:->",language) vowels=['e','a','u','o','i'] print("Old list:->",vowels) vowels.sort() print("sorted List in Assending order:->",vowels) vowels.sort(reverse=True) print("sorted List in Desending order:->",vowels) vowel=['a','e','i','u'] print("Old list:->",vowel) vowel.insert(3,'o') print("Update list:->",vowel) vowel.remove('a') print("Update list:->",vowel) os=['linux','windows','cobol'] print("Old list:->",os) os.reverse() print("Update list:->",os) OUTPUT: PROGRAM FOR BUILT-IN METHODS OF LIST Old list:-> ['Cat', 'Dog', 'Rabbit'] Updated list:-> ['Cat', 'Dog', 'Rabbit', 'Cow'] Old list:-> ['Python', 'Java', 'C++', 'C'] Updated List:-> ['Python', 'Java', 'C++'] Old list:-> ['e', 'a', 'u', 'o', 'i'] sorted List in Assending order:-> ['a', 'e', 'i', 'o', 'u'] sorted List in Desending order:-> ['u', 'o', 'i', 'e', 'a'] Old list:-> ['a', 'e', 'i', 'u'] Update list:-> ['a', 'e', 'i', 'o', 'u'] Update list:-> ['e', 'i', 'o', 'u'] Old list:-> ['linux', 'windows', 'cobol'] Update list:-> ['cobol', 'windows', 'linux'] Program No.4:Program to Demonstrate use of Dictionary. thisdict = {'NAME':'Vishal','PLACE':'Sankeshwar','USN':1711745} print("Dictonary Content=",thisdict) x = thisdict['PLACE'] print("PLACE is:->",x) print("Keys in Dictonary are:") for x in thisdict.keys(): print(x) print("Values in this dictonary are:->") for x in thisdict.values(): print(x) print("Both Keys and values of the dictonary are:->") for x,y in thisdict.items(): print(x,y) print("Total items in the dictonary:->",len(thisdict)) thisdict['District'] = 'Belagavi' print("Added new item is = ",thisdict) thisdict.pop('PLACE') print("After removing the item from dictonary=",thisdict) del thisdict['USN'] print("After deleting the item from dictonary=",thisdict) thisdict.clear() print("Empty Dictonary=",thisdict) thisdict = {‘Place’ : ‘Sankeshwar’} mydict=thisdict.copy() print("Copy of Dictonary is=",mydict) OUTPUT: Dictonary Content= {'NAME': 'Vishal', 'PLACE': 'Sankeshwar', 'USN': 1711745} PLACE is:->Sankeshwar Keys in Dictonary are: NAME PLACE USN Values in this dictonary are:-> Vishal Sankeshwar 1711745 Both Keys and values of the dictonary are:-> NAME Vishal PLACE Sankeshwar USN 1711745 Total items in the dictonary:-> 3 Added new item is= {'NAME': 'Vishal', 'PLACE': 'Sankeshwar', 'USN': 1711745, 'District': 'Belagavi'} After removing the item from dictonary= {'NAME': 'Vishal', 'USN': 1711745, 'Distict': 'Belagavi'} After deleting the item from dictonary= {'NAME': 'Vishal', 'Distict': 'Belagavi'} Empty Dictonary= {} Copy of Dictonary is= {‘Place’ : ‘Sankeshwar’} Program No.5: Program to Create SQLite Database and Perform Operations on Table. import sqlite3 conn = sqlite3.connect("test1.db") curs = conn.cursor() curs.execute("create table if not exists emp10(id integer,name text)") curs.execute("insert into emp10(id,name) values(101,'Hari')") curs.execute("insert into emp10(id,name) values(102,'Ravi')") curs.execute("insert into emp10(id,name) values(103,'Shashi')") print("Displaying the emp10 table") curs.execute("select *from emp10") rows = curs.fetchall() for i in rows: print (i) curs.execute("update emp10 set name='Hari-Om' where id=101") curs.execute("delete from emp10 where id=103") print("Displaying the emp10 table..AFTER UPDATE & DELETE") curs.execute("select *from emp10") rows = curs.fetchall() for i in rows: print (i) #curs.execute("truncate emp10") curs.execute("drop table emp10") conn.commit() curs.close() conn.close() OUTPUT: Displaying the emp5 table (101, 'Ravi') (101, 'Ravishannker') (101, 'Ramresh') After update and delete the records in the table Displaying the emp5 where id=103 (101, 'Rakesh') (101, 'Rakesh') (101, 'Rakesh') Table is dropped Program No.6: Program to Create a GUI using TKinter module. import tkinter as tk def show_entry_fields(): print("First Name: %s\n Last Name: %s" % (e1.get(), e2.get())) master = tk.Tk() tk.Label(master, text=" GUI ", fg="red", font=('times', 24, 'italic')).grid(row=0) tk.Label(master, text="First Name").grid(row=1) tk.Label(master, text="Last Name").grid(row=2) e1 = tk.Entry(master) e2 = tk.Entry(master) e1.grid(row=1, column=1) e2.grid(row=2, column=1) tk.Label(master, text="Select Gender:", fg="blue").grid(row=3, column=0) R1=tk.Radiobutton(master, text="Male", value=1).grid(row=4, column=0, sticky=tk.W) R2=tk.Radiobutton(master, text="Female", value=2).grid(row=4, column=1, sticky=tk.W) tk.Label(master,text = "Select Age:", fg="blue").grid(row=5, column=0) tk.Spinbox(master, from_= 18, to = 25).grid(row=5, column=1) tk.Label(master, text="Select Subject:", fg="blue").grid(row=6, column=0) tk.Checkbutton(master, text="Java").grid(row=7, column=0, sticky=tk.W) tk.Checkbutton(master, text="Python").grid(row=7, column=1, sticky=tk.W) tk.Checkbutton(master, text="PHP").grid(row=8, column=0, sticky=tk.W) tk.Checkbutton(master, text="C#.Net").grid(row=8, column=1, sticky=tk.W) tk.Label(master,text = "Select District:", fg="blue").grid(row=9, column=0) listbox = tk.Listbox(master) listbox.insert(1,"Belgaum") listbox.insert(2, "Bangalore") listbox.insert(3, "Dharawad") listbox.insert(4, "Hubli") listbox.insert(5, "Mysore") listbox.insert(6, "Mangalore") listbox.grid(row=10,column=1) tk.Button(master, text='QUIT', fg="red", bg="yellow", command=master.destroy).grid(row=11, column=0, sticky=tk.W, pady=4) tk.Button(master,text='SHOW', fg="red", bg="yellow", command=show_entry_fields).grid(row=11, column=1, sticky=tk.W, pady=4) tk.mainloop() OUTPUT: First Name: Aditya Last Name: Yadav Program No.7: Program to Demonstrate Exceptions in Python. try: print("TRY BLOCK") a=int(input("Enter a :-> ")) b=int(input("Enter b :-> ")) c=a/b except: print("EXCEPT BLOCK") print("We cannot divide by ZERO") else: print("ELSE BLOCK") print("The division of a and b is :-> ",c) print("NO EXCEPTION") finally: print("FINALLY BLOCK") print("Out of except,ELSE and FINALLY BLOCK") OUTPUT-1: TRY BLOCK Enter a :-> 10 Enter b :-> 2 ELSE BLOCK The division of a and b is :-> 5.0 NO EXCEPTION FINALLY BLOCK Out of except,ELSE and FINALLY BLOCK OUTPUT-2:I 12 TRY BLOCK Enter a :-> 10 Enter b :-> 0 EXCEPT BLOCK We cannot divide by ZERO FINALLY BLOCK -1356799 0.Out of except,ELSE and FINALLY BLOCK Program No.8: Program to Draw Line chart and Bar chart using Matplotlib. import matplotlib.pyplot as plt # from matplotlib import pyplot as plt import numpy as nmpi x = nmpi.arange(1,11) y1 = 2 * x y2 =3 * x plt.subplot(2,2,1) plt.title("LINE CHART...", color="blue") plt.grid() plt.xlabel("X-Labels",color="red") plt.ylabel("Y-Labels",color="violet") plt.plot(x,y1,color='green',linewidth=5) plt.subplot(2,2,2) plt.plot(x,y2,color='indigo',linewidth=3, linestyle=":") students = list(["AMit","Raj","Suraj","Kishan"]) marks = list([60,90,45,6]) plt.subplot(2,2,3) plt.grid() plt.title("BAR CHART...", loc='right',color="blue") plt.bar(students,marks,color="red") #plt.bar(students,marks) plt.show() OUTPUT: Program No.9: Program to Drawing Histogram and pie chart using matplotlib. import matplotlib.pyplot as mlt student_performance=["excellent","good","average","poor"] student_values=[15,20,40,10] mlt.subplot(1,2,1) mlt.pie(student_values,labels=student_performance,startangle=90,explode=[0.2,0.1,0,0],shadow=True,colors=["violet","indigo","blue","orange"]) marks=[90,92,40,60,55,44,30,20,10,54,74,82] grade_interval=[0,35,70,100] mlt.subplot(1,2,2) mlt.title(".......STUDENT......GRADE......") mlt.hist(marks,grade_interval,facecolor="cyan",rwidth=0.7,histtype="bar") mlt.xticks([0,35,70,100]) mlt.xlabel("P E R C E N T A G E ") mlt.ylabel("No. of STUDENTS...") mlt.show() OUTPUT: Program No.10: Program to create Array using NumPy and Perform Operations on Array. import numpy as np A=np.array([4,3,2,1]) print("Array elements are:->",A) min_value=np.min(A) max_value=np.max(A) mean_value=np.mean(A) print("The Maximum value is:->",min_value) print("The Maximum value is:->",max_value) print("The Mean value is:->",mean_value) A = A + 10 print("Add 10 to each element in the array:->",A) A = A*2 print("Multiply each element in the array by 2:->",A) SA=np.sort(A) print("Sorted array in ASCENDING ORDER:->",SA) print("Sorted array in DESCENDING ORDER:->",np.sort(A)[::-1]) OUTPUT: Array elements are:-> [4 3 2 1] The Maximum value is:-> 1 The Maximum value is:-> 4 The Mean value is:-> 2.5 Add 10 to each element in the array:-> [14 13 12 11] Multiply each element in the array by 2:-> [28 26 24 22] Sorted array in ASCENDING ORDER:-> [22 24 26 28] Sorted array in DESCENDING ORDER:-> [28 26 24 22] Program No.11: Program to Create DataFrame from Excel sheet using Pandas and Perform Operations on DataFrames. import pandas as pd #Create an EXCEL file “MY1.xlsx” and save it into your Project Path data = pd.read_excel('MY1.xlsx') print("\n** displaying data from dataframes**\n") print(data) print("\n**OPERATING ON DATAFRAMES**\n") print("\n1.View the first few rows of the dataframes:") print(data.head()) print("\n2.Number of rows and columns in the data frames:",end=" ") print(data.shape) print("\n3.Filtered data(Age column < 20):") filtered_data = data[data['Age'] < 20] print(filtered_data) print("\n4.Sort dataframes based on'Age' col in ascending order:") sorted_data = data.sort_values(by = 'Age', ascending = True) print(sorted_data) print("\n program closed...") ** displaying data from dataframes** Empl-Id Name Age Salary Country 0 101 Shilpa 16 25000 USA 1 102 Rajesh 17 12000 SwitzerLand 2 103 Akshata 20 45000 London 3 104 Gayatri 18 50000 Germany 4 105 Ganesh 32 60000 Australia 5 106 Ashwini 22 123456 Russia 6 107 Sangeeta 16 88888 Africa **OPERATING ON DATAFRAMES** 1.View the first few rows of the dataframes: Empl-Id Name Age Salary Country 0 101 Shilpa 16 25000 USA 1 102 Rajesh 17 12000 SwitzerLand 2 103 Akshata 20 45000 London 3 104 Gayatri 18 50000 Germany 4 105 Ganesh 32 60000 Australia 2.Number of rows and columns in the data frames: (7, 5) 3.Filtered data(Age column<20): Empl-Id Name Age Salary Country 0 101 Shilpa 16 25000 USA 1 102 Rajesh 17 12000 SwitzerLand 3 104 Gayatri 18 50000 Germany 6 107 Sangeeta 16 88888 Africa 4.Sort dataframes based on'Age' col in ascending order: Empl-Id Name Age Salary Country 0 101 Shilpa 16 25000 USA 6 107 Sangeeta 16 88888 Africa 1 102 Rajesh 17 12000 SwitzerLand 3 104 Gayatri 18 50000 Germany 2 103 Akshata 20 45000 London 5 106 Ashwini 22 123456 Russia 4 105 Ganesh 32 60000 Australia program closed...