0
Def sum(a,b): If a==0 or b==0: Return 0: Return 1+sum(a-1,b-1): Print (sum(4,2))
From python
10 ответов
+ 3
Don't add colon (:) for return statements.
+ 2
I took your code and tried to understand the logic of if. Here is a reworked version:
def sum_(a,b):
if a==0 or b==0:
return 0
else:
return 1+sum_(a-1,b-1)
print(sum_(4,2))
Please compare it with your code to find the amendments.
Colonel Cop, I would recommend you to go through the python tutorial to get the basics. It' really worth to work on it.
+ 1
Ok - so what is your question, or how can we help you?
[ Edited]: There should no python function names and so on be used as identifiers. This can cause unexpected errors or results.
Also indentation should be done properly.
0
This is my question on Python 3
0
Then please explain step wise for that reworked version
0
Please
0
Col. Any experience on recursion? Calling a function within itself? If not, let me tell you that you're using recursion here.
0
No
0
Experience
- 3
Def sum(a,b):
If a==0 or b==0:
Return 0:
Return 1+sum(a-1,b-1):
Print (sum(4,2))