1.
PROGRAM TO DEMONSTRATE USAGE OF BASIC REGULAR
EXPRESSION.
import re
txt="\n The v2 is in dharwad"
print(txt)
print("\n")
x=[Link]("[a-m]",txt)
print("to print lower case letters between a to m txt")
print(x)
print("\n")
print("to count the digits in txt")
x=[Link]("\t",txt)
print(x)
print("\n")
print("to check the first word of a txt")
x=[Link]("hello",txt)
if x:
print("yes string start with hello")
else:
print("no match")
print("to check fast word of a string")
x=[Link]("dharwad",txt)
if x:
print("yes string ends with dharwad")
else:
print("no match")
print("\n")
print("to print required letters followed by mentioned character")
x=[Link]("T.{2}",txt)
print(x)
print("\n")
print("to print following letters based on dots")
x=[Link]("Th......",txt)
print(x)
OUTPUT :
The v2 is in Dharwad
to print lower case letters between a to m txt
['h', 'e', 'i', 'i', 'd', 'h', 'a', 'a', 'd']
to count the digits in txt
[]
to check the first word of a txt
no match
to check fast word of a string
yes string ends with Dharwad
to print required letters followed by mentioned character
[]
to print following letters based on dots
['The v2 ']
2. PROGRAM TO DEMONSTRATE USE OF ADVANCED REGULAR
EXPRESSION FOR DATA VALIDATION.
import re
regex=r'\b[A-Za-z0-9._]+@[A-Za-z0-9.-]+\.[A-Z\a-z]{2,7}\b'
def check(email):
if([Link](regex,email)):
print("Vaild Email")
else:
print("Invaild Email")
if __name__=='__main__':
email="amazing3260@[Link]"
check(email)
email="[Link]@[Link]"
check(email)
email="[Link]"
check(email)
OUTPUT :
Valid Email
Valid Email
Inavalid Email
3. PROGRAM TO DEMONSTRATE USE OF LIST.
print("List creation")
numbers=[10,20,30,40]
print(numbers)
print("Accessing Elements from list using index")
print(numbers[1])
print(numbers[3])
print(numbers[1:3])
print("Add new elements to list append")
[Link](50)
print(numbers)
print("Add new elements to the list using insert")
[Link](0,5)
print(numbers)
numbers[2]=15
print("After changing the values",numbers)
del numbers[1]
print("After deleting the elements in the list is",numbers)
[Link](15)
print("After deleting the elements in the list is",numbers)
OUTPUT :
List creation
[10, 20, 30, 40]
Accessing Elements from list using index
20
40
[20, 30]
Add new elements to list using append
[10, 20, 30, 40, 50]
Add new elements to the list using insert
[5, 10, 20, 30, 40, 50]
After changing the values [5, 10, 15, 30, 40, 50]
After deleting the elements in the list is [5, 15, 30, 40, 50]
After deleting the elements in the list is [5, 30, 40, 50]
4. PROGRAM TO DEMONSTRATE USE OF DICTIONARIES.
print("Dictionary create")
oxford={"college":"[Link]","course":"BCOM"}
print(oxford)
print("length of the Dictionary")
print(len(oxford))
print("Accessing Elements from the dictionary")
print(oxford["college"])
print("To change the dictionary values")
oxford["course"]="BCA"
print("After changing the values of dictionary is",oxford)
print("To add item to dictionary")
oxford["University"]="KUD"
print("After adding item to dictionary:",oxford)
print("To delete from dictionary")
del oxford["course"]
print("After deleting item from dictionary:",oxford)
OUTPUT :
Dictionary create
{'college': '[Link]', 'course': 'BCOM'}
length of the Dictionary
2
Accessing Elements from the dictionary
[Link]
To change the dictionary values
After changing the values of dictionary is {'college': '[Link]', 'course':
'BCA'}
To add item to dictionary
After adding item to dictionary: {'college': '[Link]', 'course': 'BCA',
'University': 'KUD'}
To delete from dictionary
After deleting item from dictionary: {'college': '[Link]', 'University':
'KUD'}
5. PROGRAM TO CREATE SQLITE DATABASE AND PERFORM
OPERATIONS ON TABLES.
import sqlite3
conn=[Link]("[Link]")
[Link]("CREATE TABLE IF NOT EXISTS Customer(id integer
primary key,name text not null,age Integer);")
cursor=[Link]("select * from sqlite_master")
[Link]()
[Link]("insert into Customer values(1,'Abhi',90)")
[Link]("insert into Customer values(2,'Adi',80)")
[Link]("insert into Customer values(3,'Vinay',70)")
print("all records")
print([Link]("select * from Customer").fetchall())
[Link]("drop table if exists Customer2")
[Link]("update Customer set Name='kiran'where id=2")
print("update records")
print([Link]("select * from Customer").fetchall())
[Link]("delete from Customer where id=3")
print("after deleting the records")
print([Link]("select * from Customer").fetchall())
OUTPUT :
all record
[(1, 'Abhi', 90), (2, 'Adi', 80), (3, 'Vinay', 70)]
update records
[(1, 'Abhi', 90), (2, 'Kiran', 80), (3, 'Vinay', 70)]
after deleting the record [(1,
'Abhi', 90), (2, 'Kiran', 80)]
6. PROGRAM TO CREATE A GUI USING TKINTER MODULE.
import tkinter as tk
from tkinter import ttk
def delete_from_list():
selected_items = [Link]()
if selected_items:
for index in selected_items[::-1]: # Reverse to avoid index shifting
[Link](index)
else:
[Link]("Warning", "No item selected to delete!")
# Create the main application window
root = [Link]()
[Link]("Dropdown Menu and List Example")
[Link]("500x500")
# Function to handle dropdown selection
def on_select(event):
selected_item = dropdown_var.get()
[Link]([Link], selected_item)
# Dropdown menu setup
dropdown_var = [Link]()
dropdown_var.set("Select an option")
# Default value
options = ["Subject", "Python", "C.M.A","Business
ethics","English","Kannada","Indian Constitution","Financial education"]
dropdown_menu = [Link](root, dropdown_var, *options)
dropdown_menu.pack(pady=10)
# Button to add selected item to the list
add_button = [Link](root, text="Add to List",command=lambda:
on_select(None))
add_button.pack(pady=5)
# Listbox setup
listbox = [Link](root, height=10, width=30)
[Link](pady=10)
delete_button = [Link](root, text="Delete Selected",
command=delete_from_list)
delete_button.pack(pady=5)
# Run the application
[Link]()
OUTPUT :
7. PROGRAM TO DEMONSTRATE EXCEPTIONS IN PYTHON.
try:
numerator=10
denominator=0
result=numerator/denominator
print("result")
except:
print("error:zero division error")
finally:
print("this is finally block")
OUTPUT :
error:zero division error
this is finally block
8. PROGRAM TO DRAWING LINECHART AND BARCHART USING
MATPLOTLIB.
import [Link] as plt
import numpy as np
def linechart():
x=[1,2,3]
y=[2,4,8]
[Link]("Line Graph")
[Link]("x-axis")
[Link]("y-axis")
[Link](True)
[Link](x,y)
[Link]()
def barchart():
year=[2020,2021,2022,2023]
medals=[5,7,3,4]
[Link]("proformance in sport")
[Link]("year")
[Link]("Medals")
[Link](year,medals)
[Link]()
def main():
linechart()
barchart()
if __name__=='__main__':
main()
OUTPUT :
9. PROGRAM TO DRAWING HISTOGRAM AND PIECHART USING
MATPLOTLIB.
import [Link] as plt
import numpy as np
def histogram():
pop=[Link](0,100,100)
[Link]("Histrogram")
[Link]("x-axis")
[Link]("y-axis")
n,bins,patches=[Link](pop,bins=20)
[Link]()
def piechart():
labels=['Nokia','Samsung','Apple','Oppo']
values=[10,30,45,15]
colors=['yellow','green','red','blue']
explode=[0.3,0,0,0]
[Link]("Mobile Market Share")
[Link](values,labels=labels,colors=colors,explode=explode,startangle=180)
[Link]("equal")
[Link]()
def main():
histogram()
piechart()
if __name__=='__main__':
main()
OUTPUT :
10. PROGRAM TO CREATE ARRAY USING NUMPY AND PERFORM
OPERATION ON ARRAY.
import numpy as np
a=[Link]([1,2,3,4])
b=[Link]([5,6,7,8])
print("Array a is:",a)
print("Array b is:",b)
print("Length of the array a is:",len(a))
print("Type of array b is:",type(b))
print("Array bis",[Link],"Dimensional array")
print("sum of array a and b is:",a+b)
print("add 1 to all the elements of array b is:",b+1)
print("Maximum elements in the array a is:",[Link]())
print("Minimum elements in the array b is:",[Link]())
print("First element in array a is:",a[0])
print("Last elements in array b is:",b[-1])
print("Get the index of elements 4 in array is:",[Link](a==5))
OUTPUT :
Array a is: [1 2 3 4]
Array b is: [5 6 7 8]
Length of the array a is: 4
Type of array b is: <class '[Link]'>
Array b is 1 Dimensional array
sum of array a and b is: [ 6 8 10 12]
add 1 to all the elements of array b is: [6 7 8 9]
Maximum element in the array a is: 4
Minimum element in the array b is: 5
First element in array a is: 1
Last element in array b is: 8
Get the index of element 4 in array is: (array([], dtype=int64),)
11. PROGRAM TO CREATE DATA FRAME FROM EXCEL SHEET
USING PANDAS AND PERFORM OPERATIONS ON DATA FRAME.
import pandas as pd
df=[Link]({"name":["abhi","sudeep","omkar"],"age":[45,55,78]})
write=[Link]("[Link]")
df.to_excel(write,index=False)
[Link]()
data=pd.read_excel("[Link]")
print(data)
OUTPUT :
name age
0 abhi 45
1 sudeep 55
2 omkar 78