python_manual (1)
python_manual (1)
Roll No. 64
Experiment No. : 1
Experiment Title : Exploring basics of python like data types (strings, list, array, dictionaries, set, tuples)
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Aim : Exploring basics of python like data types (strings, list, array, dictionaries, set, tuples) and
control statements.
Program:
Aim : Write a Program to take two numbers from use and performs basic operation add, sub,
division and remainder.
OUTPUT:
Aim : Write a program to take input from user for name ,age, address and print the Person
Details.
OUTPUT:
Aim : Write a program to display the first and last colors from the following list.Given list
color_list = ["Red","Green","White" ,"Black"]
color_list=['Red','Green','White','Black']
print('First color in list',color_list[0])
print('Last color in a list is',color_list[len(color_list)- 1])
OUTPUT:
Conclusion:
We have learned about the basic of python like data types (strings, list, array, dictionaries, set,
tuples) and control statements.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 2
Experiment Title : Creating functions, classes and objects using Python. Demonstrate exception handling and
inheritance.
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Aim : Creating functions, classes and objects using Python. Demonstrate exception handling and inheritance.
Program:
class Student:
def putdata(self):
self.name=input('Enter Name of Student:')
self.age=int(input('Enter Age:'))
def display(self):
print("Name of Student:",self.name)
print("Name of Age:",self.age)
#To create object of class e=Student()
e.putdata()
e.display()
OUTPUT:
Aim : Write a program to create class and object for two employee.
OUTPUT:
Aim : Write a program for Inheritance.
OUTPUT:
Aim : Write a program for employee.
class Employee:
def putdata(self):
self.n=input('enter name:')
self.i=input('enter id:')
self.s=int(input('enter salary'))
def display(self):
print('name of Employee:',self.n)
print('Employee id is:',self.i)
print('Employee salary:',self.s)
e=Employee()
e.putdata()
e.display()
OUTPUT:
class Employee:
def init (self,name,id,salary):
self.n=name
self.i=id
self.s=salary
def display(self):
print('name of Employee:',self.n)
print('Employee id is:',self.i)
print('Employee salary:',self.s)
e=Employee('anu',123,100000)
#e.putdata()
e.display()
OUTPUT:
class A:
attr_1=10
def method1(self):
print("hello from function 1 of class A")
class B(A):
attr_2=20
def method2(self):
print("hello from function 2 of class B")
b1=B()
b1.method1()
b1.method2()
print('value of attribute_1 is:',b1.attr_1)
print('value of attribute_2 is:',b1.attr_2)
OUTPUT:
Conclusion: We have learned Basics of functions, classes, objects, exception handling and
inheritance using python.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 3
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Signature :
Date :
Experiment : 03
Program:
Aim : Write a program to append data to existing file and then display the entire file.
file1=open('sample.txt','w')
file1.write('Pravin Patil Clg')
file1=open('sample.txt','r')
print(file1.read())
OUTPUT:
file1=open('sample.txt','a')
file1.write('\n Coumputer Engg')
file1=open('sample.txt','r')
print(file1.read())
OUTPUT:
Aim: Write a program to count number of lines, words and characters in a file.
file='sample.txt'
# intialize counters
lines=words=ch=0
with open (file,'r')as file:
for line in file:
lines+=1
words+=len(line.split())
ch+=len(line)
print(f'Lines: {lines}')
print(f'Words: {words}')
print(f'characters: {ch}')
OUTPUT:
Aim : Write a program to display file available in current directory.
import os
print(os.getcwd())
#Get list of files in the current directory
files=[f for f in os.listdir(".") if os.path.isfile(f)]
#Display the file
print("Files in the current directory:")
for file in files:
print(file)
#os.listdir(".")->Lists all files & diectories in the current directory(".")
#os.path.isfile(f)-> Filters the list to include only files excluding directories)
OUTPUT:
Conclusion: By using basic python file handling functions, we successfully appended data to an existing
file, counted lines, words, and characters within a file and listed all files in the current
directory.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 4
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Signature :
Date :
Experiment : 04
Program:
OUTPUT :
Aim : Write a program for multithreading.
OUTPUT :
Aim : Write a program using multithreading to print 1-10 numbers and verify if it is even or odd.
Code:
from threading import Thread
from time import sleep
class Numbers(Thread):
def run(self):
for i in range(1,11):
sleep(1)
print(i)
class Even(Thread):
def caleven(self):
for i in range(1,11,1):
if i%2==0:
sleep(0.5)
print("Even number=",i)
def run(self):
self.caleven()
class Odd(Thread):
def calodd(self):
for i in range(1,11,1):
if i%2!=0:
sleep(1)
print("Odd number=",i)
def run(self):
self.calodd() #Creating & Stating threads
t1=Numbers()
t1.start()
t1.join()
t2=Even()
t2.start()
t3=Odd()
t3.start()
OUTPUT :
vv
Conclusion : This experiment successfully demonstrated the use of Python's multithreading feature to
print numbers 1 to 10 and identify even and odd numbers concurrently, showcasing
efficient and simultaneous task execution.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 5
Experiment Title : Creating GUI with python containing widgets such as labels, textbox, radio,
Checkboxes and custom dialog boxes.
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Signature :
Date :
Experiment : 05
Aim : Creating GUI with python containing widgets such as labels, textbox, radio, checkboxes, and custom
dialog boxes.
Program:
OUTPUT :
Aim : Write a program to create GUI containing widgets such as lable, textbox.
import tkinter as tk
root = tk.Tk()
# setting the windows size
root.geometry("600x400")
# declaring string variable
# for storing name and password
name_var = tk.StringVar()
passw_var = tk.StringVar()
# defining a function that will
# get the name and password and
# print them on the screen
def submit():
name = name_var.get()
password = passw_var.get()
print("The name is : " + name)
print("The password is : " + password)
name_var.set("")
passw_var.set("")
# creating a label for
# name using widget Label
name_label = tk.Label(root, text='Username', font=('calibre', 10, 'bold'))
# creating a entry for input
# name using widget Entry
name_entry = tk.Entry(root, textvariable=name_var, font=('calibre', 10, 'normal'))
# creating a label for password
passw_label = tk.Label(root, text='Password', font=('calibre', 10, 'bold'))
# creating a entry for password
passw_entry = tk.Entry(root, textvariable=passw_var, font=('calibre', 10, 'normal'), show='*')
# creating a button using the widget
# Button that will call the submit function
sub_btn = tk.Button(root, text='Submit', command=submit)
# placing the label and entry in
# the required position using grid
# method
name_label.grid(row=0, column=0)
name_entry.grid(row=0, column=1)
passw_label.grid(row=1, column=0)
passw_entry.grid(row=1, column=1)
sub_btn.grid(row=2, column=1)
# performing an infinite loop
# for the window to display
root.mainloop()
OUTPUT :
Aim : Write a program to create GUI containing widgets such as labels, textbox, radio, checkboxes, and
custom dialog boxes.
import tkinter as tk
from tkinter import messagebox
# Function to handle button click (for custom dialog)
def on_submit():
name = name_entry.get()
gender = gender_var.get()
agree = agree_var.get()
if not name:
messagebox.showwarning("Input Error", "Please enter your name.")
return
if gender == "":
messagebox.showwarning("Input Error", "Please select a gender.")
return
messagebox.showinfo("Submission", f"Name: {name}\nGender: {gender}\nAgreed to terms: {agree}")
# Main Window
root = tk.Tk()
root.title("Simple GUI Example")
# Label
label = tk.Label(root, text="Enter your details")
label.pack(pady=10)
# Textbox for Name
name_label = tk.Label(root, text="Name:")
name_label.pack()
name_entry = tk.Entry(root)
name_entry.pack(pady=5)
# Radio Buttons for Gender
gender_label = tk.Label(root, text="Gender:")
gender_label.pack()
gender_var = tk.StringVar()
gender_male = tk.Radiobutton(root, text="Male", variable=gender_var, value="Male")
gender_female = tk.Radiobutton(root, text="Female", variable=gender_var, value="Female")
gender_other = tk.Radiobutton(root, text="Other", variable=gender_var, value="Other")
gender_male.pack()
gender_female.pack()
gender_other.pack()
# Checkboxes for Terms Agreement
agree_var = tk.BooleanVar()
agree_checkbox = tk.Checkbutton(root, text="I agree to the terms and conditions", variable=agree_var)
agree_checkbox.pack(pady=10)
# Submit Button
submit_button = tk.Button(root, text="Submit", command=on_submit)
submit_button.pack(pady=20)
# Run the application
root.mainloop()
OUTPUT :
Conclusion: This experiment successfully demonstrated the creation of a graphical user interface (GUI)
in Python using various widgets, including labels, text boxes, radio buttons, checkboxes,
and custom dialog boxes, showcasing effective user interaction and interface design.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 6
Experiment Title : Menu driven program for data structure using built in function for link list, stack
and queue.
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Signature :
Date :
Experiment : 06
Aim : Menu driven program for data structure using built in function for link list, stack and queue.
Program :
Aim : Write a program for data structure using built in function for stack.
class Stack:
def init (self):
self.values = []
def push(self, x):
self.values.append(x) # Adds the element to the end of the list
def pop(self):
return self.values.pop() # Removes and returns the last element
# Example usage:
s = Stack()
s.push(10)
s.push(20)
s.push(30)
s.push(40)
print(s.values) # Output: [10, 20, 30, 40]
print(s.pop()) # Output: 40 (Last pushed element)
print(s.values) # Output: [10, 20, 30]
s.push(60)
print(s.values) # Output: [10, 20, 30, 60]
print(s.pop()) # Output: 60
class Stack:
def init (self):
self.values = []
def push(self, x):
self.values.append(x) # Adds the element to the end of the list
def pop(self):
return self.values.pop() # Removes and returns the last element
# Example usage:
s = Stack()
s.push(10)
s.push(20)
s.push(30)
s.push(40)
print(s.values) # Output: [10, 20, 30, 40]
print(s.pop()) # Output: 40 (Last pushed element)
print(s.values) # Output: [10, 20, 30]
s.push(60)
print(s.values) # Output: [10, 20, 30, 60]
print(s.pop()) # Output: 60
OUTPUT :
Aim : Write a program for data structure using built in function for link list.
class Node:
def init (self, data):
self.data = data
self.next = None # Pointer to the next node
class LinkedList:
def init (self):
self.head = None # Head of the list
def append(self, data):
new_node = Node(data)
if not self.head: # If the list is empty
self.head = new_node
return
last = self.head
while last.next: # Traverse to the last node
last = last.next
last.next = new_node # Link the new node
def print_list(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None") # Indicating the end of the list
# Example usage
ll = LinkedList()
ll.append(10)
ll.append(20)
ll.append(30)
ll.print_list()
OUTPUT:
Aim : Write a program for data structure using built in function for link list, stack and queue.
from collections import deque
class DataStructureMenu:
def init (self):
self.linked_list = []
self.stack = []
self.queue = deque()
def linked_list_operations(self):
while True:
print("\nLinked List Operations:")
print("1. Append")
print("2. Insert at index")
print("3. Remove")
print("4. Display")
print("5. Back to main menu")
choice = int(input("Enter choice: "))
if choice == 1:
val = input("Enter value to append: ")
self.linked_list.append(val)
elif choice == 2:
index = int(input("Enter index: "))
val = input("Enter value: ")
if 0 <= index <= len(self.linked_list):
self.linked_list.insert(index, val)
else:
print("Invalid index!")
elif choice == 3:
if self.linked_list:
val = input("Enter value to remove: ")
if val in self.linked_list:
self.linked_list.remove(val)
else:
print("Value not found!")
else:
print("List is empty!")
elif choice == 4:
print("Linked List:", self.linked_list)
elif choice == 5:
break
else:
print("Invalid choice!")
def stack_operations(self):
while True:
print("\nStack Operations:")
print("1. Push")
print("2. Pop")
print("3. Peek")
print("4. Display")
print("5. Back to main menu")
choice = int(input("Enter choice: "))
if choice == 1:
val = input("Enter value to push: ")
self.stack.append(val)
elif choice == 2:
if self.stack:
print("Popped:", self.stack.pop())
else:
print("Stack is empty!")
elif choice == 3:
if self.stack:
print("Top element:", self.stack[-1])
else:
print("Stack is empty!")
elif choice == 4:
print("Stack:", self.stack[::-1]) # Reversing to show top-to-bottom order
elif choice == 5:
break
else:
print("Invalid choice!")
def queue_operations(self):
while True:
print("\nQueue Operations:")
print("1. Enqueue")
print("2. Dequeue")
print("3. Front Element")
print("4. Display")
print("5. Back to main menu")
choice = int(input("Enter choice: "))
if choice == 1:
val = input("Enter value to enqueue: ")
self.queue.append(val)
elif choice == 2:
if self.queue:
print("Dequeued:", self.queue.popleft())
else:
print("Queue is empty!")
elif choice == 3:
if self.queue:
print("Front element:", self.queue[0])
else:
print("Queue is empty!")
elif choice == 4:
print("Queue:", list(self.queue))
elif choice == 5:
break
else:
print("Invalid choice!")
def main_menu(self):
while True:
print("\nMain Menu:")
print("1. Linked List")
print("2. Stack")
print("3. Queue")
print("4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
self.linked_list_operations()
elif choice == 2:
self.stack_operations()
elif choice == 3:
self.queue_operations()
elif choice == 4:
print("Exiting program. Goodbye!")
break
else:
print("Invalid choice!")
# Run the program
menu = DataStructureMenu()
menu.main_menu()
OUTPUT:
Conclusion : A menu-driven program using linked lists, stacks, and queues efficiently manages data.
Linked lists offer flexibility, stacks handle LIFO operations, and queues support
FIFO processes. This enhances usability while demonstrating the practical benefits of
these data structures.
DEPARTMENT OF COMPUTER ENGINEERING
CSL405: Skill Base Lab Course: Python Programming
Roll No. 64
Experiment No. : 7
Experiment Title : Creation of Simple socket for basic information exchange between server
and client.
Date of Conduction :
Date of Submission :
Max. Marks
Particulars
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Signature :
Date :
Experiment : 07
Aim: Creation of Simple socket for basic information exchange between server and client.
Program :
Aim: Creation of Simple socket for basic information exchange between server and client.
#serverdemo.py
import socket
# Server configuration
HOST = '127.0.0.1' # Localhost
PORT = 65432 # Port to listen on
# Create a socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen()
print(f"Server listening on {HOST}:{PORT}")
conn, addr = server_socket.accept()
print(f"Connected by {addr}")
# Receive data
data = conn.recv(1024).decode()
print(f"Received from client: {data}")
# Send response
response = "Hello from server!"
conn.sendall(response.encode())
# Close connection
conn.close()
server_socket.close()
OUTPUT :
Aim : Creation of Simple socket for basic information exchange between server and client.
#clientdemo.py
import socket
# Server configuration
HOST = '127.0.0.1' # Server's address
PORT = 65432 # Server's port
# Create a socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST, PORT))
# Send data
message = "Hello from client!"
client_socket.sendall(message.encode())
# Receive response
response = client_socket.recv(1024).decode()
print(f"Received from server: {response}")
# Close connection
client_socket.close()
OUTPUT :
Conclusion: This experiment successfully demonstrated the creation of a simple socket, enabling
basic communication between a server and client, showcasing the fundamentals of
network programming in Python.