-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram11.py
More file actions
41 lines (32 loc) · 1.26 KB
/
Program11.py
File metadata and controls
41 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import csv
# Appending new employee data to the CSV file
with open('myfile.csv', mode='a') as csvfile:
mywriter = csv.writer(csvfile, delimiter=',')
ans = 'y'
while ans.lower() == 'y':
eno = int(input("Enter Employee Number: "))
name = input("Enter Employee Name: ")
salary = int(input("Enter Employee Salary: "))
mywriter.writerow([eno, name, salary])
print("## Data Saved... ##")
ans = input("Add More? (Y/N): ")
# Searching for employee data in the CSV file
with open('myfile.csv', mode='r') as csvfile:
myreader = csv.reader(csvfile, delimiter=',')
ans = 'y'
while ans.lower() == 'y':
found = False
e = int(input("Enter Employee Number to search: "))
for row in myreader:
if len(row) != 0:
if int(row[0]) == e:
print("============================")
print("NAME:", row[1])
print("SALARY:", row[2])
found = True
break
if not found:
print("==========================")
print(" EMPNO NOT FOUND")
print("==========================")
ans = input("Search More? (Y/N): ")