-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator overloading plus class.py
More file actions
63 lines (45 loc) · 1.92 KB
/
operator overloading plus class.py
File metadata and controls
63 lines (45 loc) · 1.92 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
# create a class studentInfo
# create the following functions:
# 1. highest marks student info
# 2. Display all student name
# 3. Operator overloading to add student details
class studentInfo:
def __init__(self):
self.fp=open("DataStored.txt",'r')
# reading data from files
self.text=self.fp.read()
self.data=self.text.split('\n')
self.dictionary={rollno:{'name':name,'gender':gender,'marks':marks} for rollno,name,gender,marks in map(self.ConvertDict,self.data)}
# dictionary of student created
print(self.dictionary)
def ConvertDict(self,data):
self.ip=data.split(',')
return self.ip[0],self.ip[1],self.ip[2],self.ip[3]
def DisplayHighest(self):
self.markList = []
for x in self.dictionary:
self.markList.append(self.dictionary[x]['marks'])
self.maxMarks =max(self.markList)
print(self.maxMarks)
for x in self.dictionary:
if(self.dictionary[x]['marks'] == self.maxMarks):
print(self.dictionary[x])
def DisplayNames(self):
self.names=[]
for x in self.dictionary:
self.names.append(self.dictionary[x]['name'])
print(self.names)
def __add__(self,gradeList):
for x in self.dictionary:
if(int(self.dictionary[x]['marks']) > 60):
self.dictionary[x]['grade'] = gradeList[0]
elif(int(self.dictionary[x]['marks'] >40) and int(self.dictionary[x]['marks']) <= 60):
self.dictionary[x]['grade'] = gradeList[1]
else:
self.dictionary[x]['grade'] = gradeList[2]
print(self.dictionary)
sts=studentInfo()
sts.DisplayHighest()
sts.DisplayNames()
gradeList=['A','B','F']
sts + gradeList