0

What I'm trying to do, Im not done with it yet, but I have this code right now:

def delete(self):
        t=1
        if isinstance(self.root,odd):
        child=self.left
        grandchild=child.right
        if self.left == self.right==None:
            return None
        if self.left==None:
            return self.right
        if self.right==None:
            return self.left
        if grandchild:
            while grandchild.right:
                child = grandchild
                grandchild = child.right
            self.data = grandchild.data
            child.right = grandchild.left
        else:
            self.left = child.left
            self.data = child.data
        return self
        if isinstance(self.root,even):

Im not done with the code, but as for the assignment, Its supposed to do 2 alternatives (pretty much the same thing, but instead of going left, then right as far as possible, im gonna go right and then left as far as possible). What I'm thinking is to add t+=1 after each loop, and if the number is odd, I want it to enter the first loop, and if its even, I want it to enter the other loop (I haven't made that one yet). Can I do this easily (for I wanted to do, if isinstance(t,even) and if isinstance(t,odd) but python doesnt seem to have this syntax? Any ideas?

A.Maine
  • 41
  • 8

1 Answers1

3

From what I understood, you want to figure whether t is odd or even.

You should use the % (Modulo) operator.

if t%2 == 0: # then it is even (divisible by 2)
if t%2 == 1: # it is odd (not divisible by 2)

I hope this answers your question.

Community
  • 1
  • 1
tamirse
  • 197
  • 2
  • 10