0% found this document useful (0 votes)
35 views2 pages

Python CSV Employee Management Program

Uploaded by

Max
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)
35 views2 pages

Python CSV Employee Management Program

Uploaded by

Max
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

Program

Ques on. To write a Python program Create a CSV file to store


Emp.no, Name, Salary and search any Emp.no and display , Name,
Salary and if not found display appropriate message.
Source Code:
import csv

def Create():

F = open("Emp.csv", 'a', newline="")

W = csv.writer(F)

opt = 'y'

while opt == 'y':

No = int(input("Enter Employee Number: "))

Name = input("Enter Employee Name: ")

Sal = float(input("Enter Employee Salary: "))

L = [No, Name, Sal]

W.writerow(L)

opt = input("Do you want to con nue (y/n)?: ")

F.close()

def Search():

F = open("Emp.csv", 'r')

no = int(input("Enter Employee number to search: "))

found = 0

row = csv.reader(F)

for data in row:

if data[0] == str(no):

print("\nEmployee Details are:")

print("Name:", data[1])

print("Salary:", data[2])

found = 1
break

if found == 0:

print("Employee not found.")

F.close()

Output:
For create()

For Search()

You might also like