简体   繁体   中英

How to check if python function return true or false

I am trying to run this code but getting an error:我面临的错误

My code:

class Student:
    def __init__(self, student_id, marks,age):
       self.student_id=student_id
       self.marks=marks
       self.age=age

    def validate_age(self):
        if self.age >20:
            return True
        else:
            return False
    def validate_marks(self):
        if self.marks>0 and self.marks<100:
            return True
        else:
            return False
    def check_qualification(self):
        if (validate_age)==True and if(validate_marks)==True:
            if self.marks>65:
                return True
            else:
                return False
    def set(self,x):
        self.__student_id=x

    def get(self):
        if (check_qualification==True):
            return True
        else:
            return False

It looks to me like you could just change the line

if (validate_age)==True and if(validate_marks)==True:

to

if self.validate_age() and self.validate_marks():

Note that, since those functions already return booleans, it's redundant to add == True . It's enough to simply call the functions.

You'll probably also have to change the line in get()

if (check_qualification==True):

to

if self.check_qualification():

The compiler is getting confused because you're not actually calling the functions in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM