jeudi 27 octobre 2016

function return none instead of return number

I create a function that compare with x and y variable. Inside the function has a lots of nested elif to compare the x and y then return integer. The problem is right now, when it runs at the certain elif statement, it didn't execute the statement although the statement is correct.

def convertTo(self, x, y):
    if( x == 0 & y == 0):
        return 0
    if( x == 0 & y == 1):
        return 1
    if( x == 0 & y == 2):
        return 2
    if( x == 0 & y == 3):
        return 3
    if( x == 1 & y == 0): 
        return 4 # Didn't return this line even though x = 1 and y = 0
    else
        return None

def main():
    self.convertTo(0,0)
    self.convertTo(0,1)
    self.convertTo(0,2)
    self.convertTo(0,3)
    self.convertTo(1,0) # return None? Why?

Aucun commentaire:

Enregistrer un commentaire