为什么这导致无法分配给操作员错误?

时间:2017-08-17 21:22:51

标签: python python-3.x

为什么"不能分配给运营商"此行point * hours = QP的错误?

class Student(object):
    def __init__(self, name, surname, grade, hours, QP):
        self.name = name
        self.surname = surname
        self.grade = grade
        self.hours = hours
        self.QP = QP
    def getName(self):
        return '{}'.format(self.name)

    def getSurname(self):
        return '{}'.format(self.surname)

    def getGrade(self):
        return list(zip(self.grade, self.hours))

    def getHours(self):
        return '{}'.format(self.hours)
    def point(self):
        if grade == A:
            point = 4.0
        elif grade == B:
            point = 3.0
        elif grade == C:
            point = 2.0
        elif grade == D:
            point = 1.0
        else:
            point = 0.0

    def getQPoints(self):
        point * hours = QP
        return QP

    stud1 = Student("John","Brown",["A","B","A"],["15.0","25.0","20.0"],"")
    stud2 = Student("Mary","Watson",["C","A","B"],["15.0","25.0","20.0"],"")

    print (stud1.getQPoints())

2 个答案:

答案 0 :(得分:2)

我不相信你可以扭转这种局面。相反,做

QP = point * hours

这样,您实例化新变量,并将其设置为点和小时的乘积。

其他一些问题:你的点变量也没有被定义。你需要

self.point = point

以将变量作为实际变量。此外,它可能会导致点函数和点变量之间的混淆,因为这两个名称相同。其中一个,我将其命名为分数。

答案 1 :(得分:0)

如果我明白你想做什么: 您正试图将points * hours分配给QP,这在python中是不可能的,因此您必须按照以下方式执行此操作:

`QP = points * hours`