Please, explain me why none? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

14th Nov 2019, 11:12 AM
Nazar Pshenov
Nazar Pshenov - avatar
16 Answers
+ 8
You didn't return anything in both of the else statements
14th Nov 2019, 11:15 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 6
What should your code do ?
14th Nov 2019, 11:18 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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
14th Nov 2019, 11:26 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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
14th Nov 2019, 11:36 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Thanks! I made return for else and it's ok
14th Nov 2019, 12:05 PM
Nazar Pshenov
Nazar Pshenov - avatar
+ 1
I believe you can handle this situation. Advise you use debugger in IDE like VSCODE, and go step in your function.
16th Nov 2019, 12:47 AM
Denis Trofimov
Denis Trofimov - avatar
+ 1
Nothing is returned in any of your else statements
16th Nov 2019, 5:43 AM
Chandan Pandey
Chandan Pandey - avatar
0
Please tell me what and how I should return? Thank you!
14th Nov 2019, 11:17 AM
Nazar Pshenov
Nazar Pshenov - avatar
0
We need to be elevated to a degree
14th Nov 2019, 11:22 AM
Nazar Pshenov
Nazar Pshenov - avatar
0
You know, I just started learning programming, and I don't quite understand the word "recursive." Is it how?)
14th Nov 2019, 11:32 AM
Nazar Pshenov
Nazar Pshenov - avatar
0
Maybe you could replace both appearances of "a = step(a, b, c)" with "return step(a, b, c)".
14th Nov 2019, 12:25 PM
Seb TheS
Seb TheS - avatar
0
answer = 0 and you said print answer
16th Nov 2019, 4:44 AM
Mohamed
0
Mohamed where did the line before the last line go ?
16th Nov 2019, 4:45 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Actually answer is None
16th Nov 2019, 4:49 AM
Mohamed
0
Mohamed thanks for your explanation
16th Nov 2019, 5:01 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Chandan Pandey thanks for repeating what had already been said
16th Nov 2019, 5:50 AM
Aymane Boukrouh
Aymane Boukrouh - avatar