+ 1

Please Help!

def G(x, b): if x == b: return 0 return 1 + G(x+1, b) print("G({},{}) = {}".format(3,100, G(3, 100))) I would like to know why 'G(3,100) = 97'?

18th May 2020, 4:45 PM
Robert S. Soto
Robert S. Soto - avatar
2 Antworten
+ 1
x=3 b=100 At return 1+G(4,100) At return 96+G(99,100) 99 is passed to x which isn't equal to b So now return is 97(G(100,100) Now 100 is passed to x which equals to b so 0 is returned return 97+0 So 97
18th May 2020, 4:53 PM
Abhay
Abhay - avatar
+ 1
Thank you Abhay.
18th May 2020, 5:10 PM
Robert S. Soto
Robert S. Soto - avatar