0% found this document useful (0 votes)
514 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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
514 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 DOCX, PDF, TXT or read online on Scribd

Program

Question. 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.lower() == '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 continue (y/n)?: ')

F.close()

def Search():

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

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('----------------------------')

print('Name:', data[1])
print('Salary:', data[2])

print('----------------------------')

Found = 1

break

if Found == 0:

print('Employee not found.')

F.close()

Create()

Search()

Output:
For create()

For Search()

You might also like