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
How to Access a Standard-Library Module in Python When There Is a Local Module with the Same Name
Assigning String with Boolean Expression
Python Webdriver to Handle Pop Up Browser Windows Which Is Not an Alert
Embedding Ipython Qt Console in a Pyqt Application
Accessing the List While Being Sorted
Pandas Selecting by Label Sometimes Return Series, Sometimes Returns Dataframe
Tab Completion in Python's Raw_Input()
How to Trace the Path in a Breadth-First Search
MySQL "Incorrect String Value" Error When Save Unicode String in Django
Scaling of Tkinter Gui in 4K (3840*2160) Resolution
Command Executed with Paramiko Does Not Produce Any Output
Python: My Function Returns "None" After It Does What I Want It To
Resampling a Numpy Array Representing an Image
Find Substring in String But Only If Whole Words
Why Can't I Change Only a Single Element in a Nested List in Python