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

Program 13

Uploaded by

Max
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Program 13

Uploaded by

Max
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.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 con nue (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