-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathteachers.py
77 lines (63 loc) · 1.76 KB
/
teachers.py
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
#! usr/bin/python3
import association
teacher_dict=dict()
def create_input():
teacher_id=input("Please enter id of teacher :")
teacher_name=input("Please enter name of teacher :")
create_teacher(teacher_id,teacher_name)
#
def create_teacher(teacher_id,teacher_name):
if(teacher_id in teacher_dict):
print("There is already a teacher with given id")
print("To re-assign this to someone else, please consider deleting existing one")
else:
teacher_dict[teacher_id]=teacher_name
#
def view_input():
print("1.View teacher by id\n2.View all teachers")
choice=int(input("Please enter your choice :"))
if(choice==1):
teacher_id=input("Please enter teacher_id :")
view_teachers(teacher_id)
elif(choice==2):
view_teachers()
else:
print("Please enter valid choice")
view_input()
#
def view_teachers(teacher_id=None):
if(teacher_id==None):
for teacher in teacher_dict.items():
print ("Teacher Id :" ,teacher[0] ," Teacher Name :",teacher[1])
elif(teacher_id in teacher_dict):
print("Teacher Name :",teacher_dict[teacher_id])
else:
print("No such teacher exists")
#
def delete_input():
teacher_id=input("Please enter id of teacher to be deleted :")
delete_teacher(teacher_id)
#
def delete_teacher(teacher_id):
if(teacher_id not in teacher_dict):
print("No such teacher_id exists")
elif(teacher_id in association.association_dict.values()):
print("Can't delete ",teacher_dict[teacher_id] ," , assiggned to some subject")
else:
del teacher_dict[teacher_id]
#
def menu():
print("1.Create\n2.View\n3.Delete ")
choice=int(input("Please enter your choice :"))
if(choice==1):
create_input()
elif(choice==2):
view_input()
elif(choice==3):
delete_input()
else:
print("Please enter valid choice")
menu()
#
if __name__=='__main__':
menu()