You are trying to call n(m+1)
in your elif
and else
block, since you say n
is an integer, this is the problem, you should be calling mult()
function recursively sending n
and m+1
or m-1
as parameters.
Another issue is that you should convert the result of n - mult(n, m+1)
to negative before returning.
Example –
... return - (n - mult(n, m+1)) else: return n + mult(n, m-1)
Demo with example changes –
>>> mult(5,-3) -15 >>> mult(-10,-3) 30 >>> mult(5,3) 15
Related Posts:
- How to send an email with Python?
- What is the maximum recursion depth in Python, and how to increase it?
- What is the maximum recursion depth in Python, and how to increase it?
- How do I define a function with optional arguments?
- Basic explanation of python functions
- What is the naming convention in Python for variable and function names?
- Python: maximum recursion depth exceeded while calling a Python object
- What is the maximum recursion depth in Python, and how to increase it?
- Call a function from another file?
- Python Calling Function from Another File
- What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check fails)?
- IndexError: index 1 is out of bounds for axis 0 with size 1/ForwardEuler
- Apply function to each element of a list
- Python return list from function
- Python: maximum recursion depth exceeded while calling a Python object
- Python Array Rotation
- How to multiply all integers inside list
- How to stop a function
- Repeating a function in Python
- python3 TypeError: ‘function’ object is not iterable
- How to get a function name as a string?
- Python: Can a function return an array and a variable?
- Recursion in Python? RuntimeError: maximum recursion depth exceeded while calling a Python object
- Call Python function from JavaScript code
- function is not defined error in Python
- Is there a math nCr function in python?
- Negation in Python
- Adding +1 to a variable inside a function
- Is there a math nCr function in python? [duplicate]
- Python Quicksort Runtime Error: Maximum Recursion Depth Exceeded in cmp
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Run function from the command line
- How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- Remove all whitespace in a string
- What is a “method” in Python?
- How to generate all permutations of a list?
- Is there a Python equivalent to Ruby’s string interpolation?
- Python Progress Bar
- Most efficient way to find mode in numpy array
- Python error “ImportError: No module named”
- How to groupby based on two columns in pandas?
- How do I append one string to another in Python?
- Python Progress Bar
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Python: list of lists
- How can I split and parse a string in Python?
- numpy matrix vector multiplication
- Creating a basic auto clicker in python
- What’s the difference between torch.stack() and torch.cat() functions?
- proper name for python * operator?
- How to do superscripts and subscripts in Jupyter Notebook?
- How do I unload (reload) a Python module?
- ImportError: No module named PIL
- Maximum and Minimum values for ints
- How do I list all files of a directory?
- What does axis in pandas mean?
- Dynamically growing a python array when assigning to it
- “OverflowError: Python int too large to convert to C long” on windows but not mac
- Can’t compare naive and aware datetime.now() <= challenge.datetime_end
- List of zeros in python
- How to remove an element from a list by index
- How to add title to subplots in Matplotlib
- ‘pip3’ is not recognized as an internal or external command, operable program or batch file
- How to display text in pygame?
- Python Nested Loops To Print Rectangle With Asterisks
- How to fix this strange error: “RuntimeError: CUDA error: out of memory”
- Generate random sentences in python
- Combine two columns of text in pandas dataframe
- How can I rename a conda environment?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Relative paths in Python
- Convert bytes to int?
- SQLAlchemy ORDER BY DESCENDING?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Relative paths in Python
- AttributeError(“‘str’ object has no attribute ‘read'”)
- Asyncio.gather vs asyncio.wait
- Loop backwards using indices in Python?
- Why do I get a “referenced before assignment” error when assigning to a global variable in a function?
- Python: count repeated elements in the list
- Is there a “do … until” in Python?
- Printing variables in Python 3.4
- Meaning of @classmethod and @staticmethod for beginner?
- Haversine Formula in Python (Bearing and Distance between two GPS points)
- Replacing a character from a certain index
- ValueError: Expected object or value when reading json as pandas dataframe
- Histogram plotting “AttributeError: max must be larger than min in range parameter.”
- Python TypeError: non-empty format string passed to object.__format__
- AttributeError: ‘Series’ object has no attribute ‘reshape’
- Repeated “Kernel died, restarting” forever
- TypeError: decoding str is not supported
- How to do a Sigma in python 3
- Converting Pandas dataframe into Spark dataframe error
- ImportError: no module named win32api
- Print series of prime numbers in python
- How to print a specific row of a pandas DataFrame?
- Python code to remove HTML tags from a string
- Sorting list based on values from another list