Part – B
1. Implement python script to remove duplicates from a list
2. Implement python script to find the repeated items of a tuple
3. Implement python script to check whether a given key already
exists or not in a dictionary
4. Write a python script to implement method overloading
5. Create SQLite Database and Perform Operations on Tables
6. Create a GUI using Tkinter module
7. Drawing Line chart and Bar chart using Matplotlib
8. Drawing Histogram and Pie chart using Matplotlib
9. Create Array using NumPy and Perform Operations on Array
[Link] DataFrame from Excel sheet using Pandas and Perform
Operations on DataFrames
1. Implement python script to remove duplicates from a list
numbers = [1, 2, 3, 2, 4, 1, 5]
unique_list = [ ]
for num in numbers:
if num not in unique_list:
unique_list.append(num)
print(“Original List”, numbers)
print(“List without duplicates:”, unique_list)
OUTPUT:
Original list: [ 1, 2, 3, 2, 4, 1, 5 ]
List without duplicates: [ 1, 2, 3, 4, 5 ]
2. Implement python script to find the repeated items of a
tuple
tup = (1, 2, 3, 4, 2, 5, 3, 6, 1)
repeated_items = [ ]
for item in tup:
if [Link](item) > 1 and item not in repeated_items:
repeated_items.append(item)
print(“Tuple:”, tup)
print(“Repeated items in the tuple:”, repeated_items)
OUTPUT:
Tuple: ( 1, 2, 3, 4, 2, 5, 3, 6, 1 )
Repeated items in the tuple: [ 1, 2, 3 ]
3. Implement python script to check whether a given key
already exists or not in a dictionary
my_dict = {“name”: “Rama”, “age”: 20, “city”: “Mysore”}
key = input(“Enter the key to check: “)
if key in my_dict:
print(f‘key “{key}” exists in the dictionary’)
else:
print(f‘Key “{key}” does not exists in the dictionary’)
OUTPUT:
Enter the key to check: age
Key ‘age’ exists in the dictionary
Enter the key to check: country
Key ‘country’ does not exists in the dictionary
4. Write a python script to implement method overloading
class MathOperations:
def add(self, a, b, c=0):
return a + b + c
math = MathOperations ( )
print(“Add 2 numbers”, [Link] (5, 10) )
print(“Add 3 numbers”, [Link] (5, 10, 15) )
OUTPUT:
Add 2 numbers: 15
Add 3 numbers: 30
5. Create SQLite Database and Perform Operations on Tables
import sqlite3
with [Link]("[Link]") as conn:
cur = [Link]()
[Link](“””
CREATE TABLE IF NOT EXISTS STUDENT(
id INTEGER PRIMARY KEY,
name TEXT ,
marks INTEGER
)
“””)
[Link] (“DELETE FROM STUDENT”)
[Link](“INSERT INTO STUDENT VALUES (1, 'VASU', 48)”)
[Link](“INSERT INTO STUDENT VALUES (2, 'Karthik', 50)”)
print (“ Student Table Records :”)
print( ‘ID\t’, ‘NAME\t’, ‘MARKS’)
[Link] (“SELECT * FROM student “)
rows = [Link]()
for row in rows:
print(row)
OUTPUT:
Student Table Records :
ID NAME MARKS
(1, ‘Vasu’, 40)
(2, ‘karthik’, 50)
6. Create a GUI using Tkinter module
import tkinter as tk
from tkinter import messagebox
def show_message( ) :
[Link] (“Hello”, ”Welcome to the GUI!” )
window = [Link] ( )
[Link] (“My GUI”)
[Link] (“300x200”)
label = [Link] (window, text=”Hello, World!” )
[Link] ( )
button=[Link](window, text=”Click Me”, command=show_message)
[Link] ( )
[Link] ( )
NOTE: In the above program geometry(300x200) here x is small
letter x
7. Drawing Line chart and Bar chart using Matplotlib
import pandas as pd
import [Link] as plt
[Link] [ “[Link]” ] = [ 7.50, 3.50 ]
[Link] [ “[Link]” ] = True
df = [Link] (dict (data = [2,4,1,5,9,6,0,7] ) )
fig, ax = [Link] ( )
df [ ‘data’ ] .plot ( kind=’bar’, color =’red’ )
df [ ‘data’ ] .plot ( kind=’line’, marker=’*’, color=’black’, ms=10)
[Link] ( )
8. Drawing Histogram and Pie chart using Matplotlib
import [Link] as plt
data = [ 5, 10, 12, 8, 7, 3, 5, 2, 7, 9, 6, 4, 5, 3, 6, 7, 8, 10 ]
labels, sizes = [ ‘A’, ‘B’, ‘C’, ‘D’, ‘E’ ], [ 15, 30, 20, 10, 25 ]
fig, axes = [Link] (1, 2, figsize= (10, 5 ) )
axes [0].hist (data, bins=5, color=’skyblue’, edgecolor=’black’)
axes [0].set (title=’Histogram’, xlabel=’Values’, ylabel=’Frequency’)
axes[1].pie(sizes,labels=labels,autopct=’%1.1f%%’,colors=[‘red’,’green’,
‘blue’, ‘orange’, ‘purple’] )
axes [1].set_title(‘Pie Chart’)
plt.tight_layout ( )
[Link] ( )
9. Create Array using NumPy and Perform Operations on Array
import numpy as np
arr, arr1 = [Link]([7, 16, 25]), [Link]([4, 8, 6])
print(f”First array: {arr} \nSecond array: {arr1}”)
print(f”Addition: {[Link](arr, arr1) }”)
print(f”Subtraction: {[Link](arr, arr1) }”)
print(f”Multiplication: {[Link](arr, arr1) }”)
print(f”Division: {[Link](arr, arr1) }”)
print(f”Modulus: {[Link](arr, arr1) }”)
print(f”Power: {[Link](arr, 2) }”)
OUTPUT:
First array: [ 7 16 25 ]
Second array: [ 4 8 6 ]
Addition: [ 11 24 31 ]
Subtraction: [ 3 8 19 ]
Multiplication: [ 28 128 150 ]
Division: [ 1.75 2 4.16666667 ]
Modulus: [ 3 0 1 ]
Power: [ 49 256 625 ]
10. Create DataFrame from Excel sheet using Pandas and Perform
Operations on DataFrames
import pandas as pd
data={
'ID':[1,2,3],
'Name':['Anjana', 'Priya', 'Sivan'],
'Marks':[96,69,87]
}
df=[Link](data)
df.to_excel('[Link]',sheet_name='Student Data', index=False)
print("Excel file '[Link]' created successfully!")
print("\n Data in the file:")
print(df)
try:
df=pd.read_excel('[Link]')
print("Data Frame:")
print(df)
print("\n Average marks:")
print(df['Marks'].mean())
print("\n Maximum marks:")
print(df['Marks'].max())
print("\n Minimum marks:")
print(df['Marks'].min())
except FileNotFoundError:
print("Error: '[Link]' file not found. Please run step1 first")
except Exception as e:
print(f"An error occurred: {e}")
OUTPUT:
Excel file '[Link]' created successfully!
Data in the file:
ID Name Marks
0 1 Anjana 96
1 2 Priya 69
2 3 Sivan 87
Data Frame:
ID Name Marks
0 1 Anjana 96
1 2 Priya 69
2 3 Sivan 87
Average marks:
84.0
Maximum marks:
96
Minimum marks:
69