Python Pip Install Throws Typeerror: Unsupported Operand Type(S) for -=: 'Retry' and 'Int'

TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' during PIP upgrade

This happens to me when I am behind a corporate proxy. To fix that, run with --proxy=urlOfYourProxy.

For example:

pip install --proxy user:password@http://localproxy:8080

TypeError: unsupported operand type(s) for %: 'BinaryTreeNode' and 'int'

The immediate cause of your error is that your code is doing this: if root.left%2==0:. But root.left, as the message says, is a BinaryTreeNode which you can't take a mod of. Or it could be None, ditto.

You could do if root.left.data %2 == 0: to make that error go away, but that is unnecessarily complicated and will lead to difficulty, because as it stands your code only sets n and b conditionally, but calls sumRecursive(n) and sumRecursive(b) unconditionally, so you will end up with undefined local variable errors. So leave that test to the recursive call, which your function is doing already with if root.data % 2 == 0:, and do this instead:

def sumRecursive(root):
if not root:
return 0
if root.data % 2 == 0:
m = root.data
else:
m = 0
n = sumRecursive(root.left)
b = sumRecursive(root.right)
return m + n + b

sumRecursive(root)
8


Related Topics



Leave a reply



Submit