我知道在这方面有语法错误的问题,但我不能在这里解决这个问题。为什么它给了我下面的语法错误?你知道吗
更新:现在第55行出现语法错误 Module=namedtuple('Module','code title ects')
BB1_MODULES = {
'BB103': Module('BB103', 'Computer Systems', 5),
'BB111': Module('BB111', 'Web Design', 5),
'BB112': Module('BB112', 'Digital Innovation', 5),
'BB123': Module('BB123', 'Computer Programming I', 10),
'BB124': Module('BB124', 'Computer Programming II', 10),
'BB343': Module('BB343', 'Networks and Internet', 5),
'BB434': Module('BB434', 'Operating Systems', 5),
'BB543': Module('BB543', 'Problem Solving', 5),
'BB432': Module('BB432', 'IT Mathematics', 10)}#ects
class Student(object):
def __init__(self, idnum, surname, firstname, mods=CA1_MODULES):
self.__idnum = idnum
self.__surname = surname
self.__firstname = firstname
self.__mods = mods
self.__marks = {code: 0 for code in self.__mods.keys()} #returm a list of module codes #dict comprehension
# self.__total_credits
self.__total__credits = sum[mod.ects for mod in self.__mods.values()]
def __str__(self):
name = '{} : {} {}'.format(self.__idnum,
self.__firstname,
self.__surname)
uline = '-' * len(name)
results = '\n'.join([code + ' : ' + self.__mods[code].title +
' : ' + str(self.__marks[code])
for code in sorted(self.__mods.keys())])
pm = 'Precision mark: {:.2f}'.format(self.precision_mark())
if self.passed():
outcome = 'Pass'
elif self.passed_by_compensation():
outcome = 'Pass by compensation'
else:
outcome = 'Fail'
return '\n'.join([name, uline, results, pm, outcome])
def add_mark(self, module, mark):
self.__marks[module]=mark
def precision_mark():
[self.__marks[mod] * self.__mods[code].ects for code in self.__mods.keys()] / self.__total_credits
def passed():
return min(self__marks.values()) >= 40
def passed_by_compensation():
if self.precision_mark() <45:
return False
sum([self.__mods[code].ects for code in self.__mods.keys() if self.marks[code] < 40]) > self.__total_credits / 6:
return False
return min(self.marks.__values()) >= 35
self.__total__credits = sum[mod.ects for mod in self.__mods.values()]
^
#SyntaxError: invalid syntax
#self.__total__credits = sum[mod.ects for mod in self.__mods.values()]
sum
是一个函数,因此必须使用括号:相关问题 更多 >
编程相关推荐