0% found this document useful (0 votes)
7 views

python_manual (1)

The document outlines a series of Python programming experiments conducted by a student named Yashvi Nilesh Bari during the fourth semester of 2024-2025. Each experiment focuses on different aspects of Python, including data types, functions, classes, file handling, threading, and GUI creation, with specific aims, programs, and conclusions provided for each. The document also includes grading criteria and verification by the faculty member, Prof Manjula Athani.

Uploaded by

Yashvi Bari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

python_manual (1)

The document outlines a series of Python programming experiments conducted by a student named Yashvi Nilesh Bari during the fourth semester of 2024-2025. Each experiment focuses on different aspects of Python, including data types, functions, classes, file handling, threading, and GUI creation, with specific aims, programs, and conclusions provided for each. The document also includes grading criteria and verification by the faculty member, Prof Manjula Athani.

Uploaded by

Yashvi Bari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

DEPARTMENT OF COMPUTER ENGINEERING

CSL405: Skill Base Lab Course: Python Programming

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

Roll No. 64

Experiment No. : 1

Experiment Title : Exploring basics of python like data types (strings, list, array, dictionaries, set, tuples)

and control statements.

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani


Signature :
Date :
Experiment : 01

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.

num1=int(input('Enter the 1st no:'))


num2=int(input('Enter the 2nd No:',))
print('Addition of number is',(num1+num2))
print('Subtraction of number is',(num1-num2))
print('Division of number is',(num1/num2))
print('Remainder of number is',(num1%num2)

OUTPUT:

Aim : Write a program to take input from user for name ,age, address and print the Person
Details.

name=input('Enter the name of person:')


age=int(input('Enter the age of person:'))
add=input('Enter the Address of the person:')
print('-------Persons Details ')
print('Persons Name is:',name,'\n','Persons age is:',age,'\n','Persons Address is:',add)

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani


Signature :
Date :
Experiment : 02

Aim : Creating functions, classes and objects using Python. Demonstrate exception handling and inheritance.

Program:

Aim : Write a program to create a class and object.

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 employee.

Code: class Employee:


def putdata(self):
self.name=input('Name of Employee:')
self.dept=input('enter dept:')
self.salary=int(input('enter Salary:'))
def display(self):
print("Name of Employee:",self.name)
print("enter dept:",self.dept)
print("enter salary:",self.salary)
#To create object of class
e=Employee()
e.putdata()
e.display()
OUTPUT:

Aim : Write a program to create class and object for two employee.

Code: class Employee:


def putdata(self):
self.name=input('Name of Employee:')
self.dept=input('enter dept:')
self.salary=int(input('enter Salary:'))
def display(self):
print("Name of Employee:",self.name)
print("enter dept:",self.dept)
print("enter salary:",self.salary)
#To create object of class
e1=Employee()
e1.putdata()
e2=Employee()
e2.putdata()
e1.display()
e2.display()

OUTPUT:
Aim : Write a program for Inheritance.

Code: class Person:


def init (self, name="", age=0): # Correct constructor definition
self.name = name
self.age = age
def read_data(self): # Method to read person data
self.name = input("Enter Name: ")
self.age = int(input("Enter age: "))
def put_data(self): # Method to display person
print("Name of Person:", self.name)
print("Age of Person:", self.age)
class Student(Person): # Class name should start with capital letter
def init (self, name="", age=0, rollno=0, per=0.0): # Correct constructor
super(). init (name, age) # Call the parent class constructor
self.rollno = rollno # Correctly assign rollno
self.per = per # Correctly assign percentage
def read_student(self): # No parameters needed
self.read_data() # Call the parent class method
self.rollno = int(input('Enter rollno: ')) # Read roll number
self.per = float(input('Enter percentage: ')) # Read percentage
def put_student(self): # Method to display student data
super().put_data() # Display person data
print("Roll no:", self.rollno) # Display roll number
print("Percentage:", self.per) # Display percentage

# Creating an instance of Student and using its methods


s = Student() # Create a Student instance
s.read_student() # Read student data
s.put_student() # Output student data

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:

Aim : Write a program to assign values for employee.

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:

Aim : Write a program for attribute.

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

Roll No. 64

Experiment No. : 3

Experiment Title : Exploring Files and directories.


a) Python Program to append data to existing file and then display the entire file.
b) Python Program to count number of lines, words and characters in a file.
c) Python Program to display file available in current directory.

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani

Signature :

Date :
Experiment : 03

Aim : Experiment Title : Exploring Files and directories.


a) Python Program to append data to existing file and then display the entire file.
b) Python Program to count number of lines, words and characters in a file.
c) Python Program to display file available in current directory.

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

Roll No. 64

Experiment No. : 4

Experiment Title : Programs on Threading using Python.

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani

Signature :

Date :
Experiment : 04

Aim : Programs on Threading using Python.

Program:

Aim : Write a program for multithreading.

from threading import Thread


from time import sleep
class A(Thread):
def run(self):
for i in range(5):
sleep(1)
print("Anisha")
class C(Thread):
def run(self):
for i in range(5):
sleep(1)
print("Akanksha")
t1=A()
t1.start()
t2=C()
t2.start()
print("Aparna")

OUTPUT :
Aim : Write a program for multithreading.

from threading import Thread


from time import sleep
class A(Thread):
def run(self):
for i in range(5):
sleep(1)
print("Anisha")
class C(Thread):
def run(self):
for i in range(5):
sleep(1)
print("Akanksha")
t1=A()
t1.start()
t1.join()
t2=C()
t2.start()
print("Aparna")

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani

Signature :

Date :
Experiment : 05

Aim : Creating GUI with python containing widgets such as labels, textbox, radio, checkboxes, and custom
dialog boxes.

Program:

Aim: Write a program to create GUI containing widgets such as lable.

from tkinter import *


root=Tk()
root.title("Welcome to GUI programming")
root.geometry('350x280')
lbl= Label(root,text="Are you PRP student")
lbl.grid(column=1, row=1)
lbl.pack()
btn=Button(root,text='yes', fg='cyan', command=root.destroy)
btn.pack()
root.mainloop()

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani

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

Fourth Semester, 2024-2025 (Even Semester)

Name of Student : Yashvi Nilesh Bari

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

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations


(1 Mark)

Checked and Verified by

Name of Faculty : Prof Manjula Athani

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.

You might also like