-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopPy.py
More file actions
106 lines (83 loc) · 3.14 KB
/
oopPy.py
File metadata and controls
106 lines (83 loc) · 3.14 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# OOP in PYTHON implementation
class Employee(object):
def __init__(self, EmpNo, EmpName, Post, salary, Department):
self.EmpNo = EmpNo
self.EmpName = EmpName
self.Post = Post
self.salary = salary
self.Department = Department
def DisplayData(self):
print(self.EmpNo, " ", self.EmpName, " ", self.Department, " ", self.Post, " ", self.salary)
k = 0
EmpList = []
for i in range(3):
name = input("Enter the name of emplyee %i " % (i + 1))
post = input("Enter the post of emplyee %i " % (i + 1))
salary = input("Enter the salary of emplyee %i " % (i + 1))
Department = input("Enter the department of empl0yee %i " % (i + 1))
num = i + 1
EmpList.append(Employee(num, name, post, salary, Department))
k = i + 1
for i in range(3):
# print(EmpList[i].EmpName)
EmpList[i].DisplayData()
def AddEmployee():
name = input("Enter the name of new emplyee")
post = input("Enter the post of new emplyee")
salary = input("Enter the salary of new employee")
Department = input("Enter the department of employee")
global k
num = k + 1
k = k + 1
EmpList.append(Employee(num, name, post, salary, Department))
for n in range(k):
# print(EmpList[i].EmpName)
EmpList[n].DisplayData()
def DeleteEmployee():
num1 = int(input("Enter employee number, to delete it from list"))
for j in range(k - 1):
if (num1 == EmpList[j].EmpNo):
del EmpList[j]
for n in range(k - 1):
# print(EmpList[i].EmpName)
EmpList[n].DisplayData()
def updatedetails():
num1 = int(input("Enter employee number, to update its data"))
count = 0
for j in range(k - 1):
if num1 == EmpList[j].EmpNo:
EmpList[j].EmpName = input("Enter the updated name of employee ")
EmpList[j].Post = input("Enter the updated post ")
EmpList[j].salary = input("Enter the updated salary ")
EmpList[j].DisplayData()
count += 1
if count == 0:
print("Eployee doesnt exist!!")
def searchEmployee():
num1 = int(input("Enter employee number, to search"))
count = 0
for j in range(k - 1):
if num1 == EmpList[j].EmpNo:
EmpList[j].DisplayData()
choice = 0
while choice != 6:
print("MENU:\n1-ADD NEW EMPLOYEE\n2-DELETE AN EMPLOYEE")
print("4-UPDATE FIELDS OF EMPLOYEE\n5-SEARCH EMPLOYEE\n6-EXIT")
choice = int(input("ENTER YOUR CHOICE: ")) # displaying menu and inputing choice
if choice == 1:
print("YOU HAVE CHOSEN: 1-ADD NEW EMPLOYEE")
AddEmployee()
elif choice == 2:
print("YOU HAVE CHOSEN: 2-DELETE AN EMPLOYEE")
DeleteEmployee()
elif choice == 4:
print("YOU HAVE CHOSEN: 4-UPDATE FIELDS OF EMPLOYEE")
updatedetails()
elif choice == 5:
print("YOU HAVE CHOSEN: 5-SEARCH EMPLOYEE")
searchEmployee()
elif (choice == 6):
print("YOU HAVE CHOSEN: 6-EXIT")
break
else: # default case: wrong input of choice
print("Wrong input of choice")