Answer the question
In order to leave comments, you need to log in
Why is only the latest data added to the dictionary?
When you try to add data to the dictionary using the put method, only the last entered value is saved (when the count method is displayed, it will give 1, although there are many more surnames). Plus, the __str__ method doesn't output anything at all. What could be the problem? Thanks in advance.
class Vedomost(object):
def __init__(self, dis, group):
self.__dis = dis
self.__group = group
self.__ved = {}
@property
def ved(self):
return self.__ved
@property
def dis(self):
return self.__dis
@property
def group(self):
return self.__group
def __str__(self):
return '{0:10} <=> {1:10} <=> {2:10}'.format(self.__dis, self.__group, self.__ved)
def put(self, fam, mark):
self.__ved.update(fam = mark)
def get(self, fam):
return self.__ved.get(fam)
def change(self, fam, mark):
self.__ved[fam] = mark
def delete(self, fam):
del self.ved[fam]
def result(self):
exc = 0
good = 0
nb = 0
bad = 0
nz = 0
for key in self.ved:
if self.__ved[key] == 'отл':
exc += 1
elif self.__ved[key] == 'хор':
good += 1
elif self.__ved[key] == 'уд':
nb += 1
elif self.__ved[key] == 'неуд':
bad += 1
elif self.__ved[key] == 'н':
nz += 1
return (exc, good, nb, bad, nz)
def count(self):
return len(self.__ved)
def names(self):
return self.__ved.keys()
his = Vedomost(dis = 'История', group = 'BI 1-1')
his.put(fam = 'Иванов', mark = 'уд')
his.put(fam = 'Артемов', mark = 'хор')
his.put(fam = 'Назаров', mark = 'отл')
his.put(fam = 'Иванчук', mark = 'неуд')
his.put(fam = 'Сидоров', mark = 'уд')
his.put(fam = 'Павлов', mark = 'отл')
his.put(fam = 'Рожков', mark = 'отл')
his.put(fam = 'Шефчук', mark = 'н')
his.put(fam = 'Морозов', mark = 'хор')
print(his.result())
print(his.count())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question