-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.py
More file actions
74 lines (55 loc) · 1.81 KB
/
Student.py
File metadata and controls
74 lines (55 loc) · 1.81 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
class DictionaryData:
def __init__(self):
self.dictionary = {}
def update_marks(self, new_marks, key):
if key in self.dictionary:
self.dictionary[key] = new_marks
return "Success"
return "This student doesnt exist. Please check the spelling"
def remove_student(self, student_name):
if student_name in self.dictionary:
self.dictionary.pop(student_name)
return "Success"
return "This student doesnt exist"
def add_marks(self, student_name, marks):
if student_name not in self.dictionary:
self.dictionary[student_name] = marks
return "Success"
return "This student already exists"
def show_data(self, return_type = "string"):
return_type = return_type.lower()
if return_type == "string":
all_keys = list(self.dictionary.keys())
return "\n".join([f"{key}: {self.dictionary[key]}" for key in all_keys])
else:
return self.dictionary
Modes = """
You have three modes:
a) Add
b) Remove
c) Update
d) Show
e) Exit
"""
DD = DictionaryData()
student_name = None
marks = None
def input_marks():
return [int(input(f"Enter {subject} mark: ")) for subject in ["Physics","Chemistry","Maths","Computer","English"]]
def get_student():
return input("Enter student name: ")
while True:
print(Modes)
a = input("Enter mode:").lower()
if a == "add":
print(DD.add_marks(get_student(),input_marks()))
if a == "show":
print(DD.show_data())
if a == "exit":
print("Bye")
break
if a == "remove":
print(DD.remove_student(get_student()))
if a == "update":
print(DD.update_marks(get_student(),input_marks()))
print("-"*20)