0
Please, explain me why none?
def step(a, b, c): if b == 1: k=a*c return(k) else: if b % 2 == 1: c = c*a b = b//2 a = a*a a = step(a,b,c) else: b = b//2 a = a*a a = step(a,b,c) chislo = 2 stepin = 10 answer = 0 answer = step(chislo, stepin, 1) print(answer)
16 Answers
+ 8
You didn't return anything in both of the else statements
+ 6
What should your code do ?
+ 3
Does it have to be recursive ? Anyway, you can immediatly return a at the end of both else statements assuming that you code is correct.
Also, what is the use of c variable, it seems to just multiply the output by c
+ 3
A recursive function is a function that calls itself, and it's weird that you ask this question because people don't just make recursive functions by luck.
If it does not have to be recursive, why not just:
def step(a, b, c):
return (a**b)*c
+ 1
Thanks! I made return for else and it's ok
+ 1
I believe you can handle this situation.
Advise you use debugger in IDE like VSCODE, and go step in your function.
+ 1
Nothing is returned in any of your else statements
0
Please tell me what and how I should return? Thank you!
0
We need to be elevated to a degree
0
You know, I just started learning programming, and I don't quite understand the word "recursive." Is it how?)
0
Maybe you could replace both appearances of "a = step(a, b, c)" with "return step(a, b, c)".
0
answer = 0 and you said print answer
0
Mohamed where did the line before the last line go ?
0
Actually answer is None
0
Mohamed thanks for your explanation
0
Chandan Pandey thanks for repeating what had already been said