def gcd(a,b):
if b == 0:
return a
elif a < b:
return gcd(b,a)
else:
return gcd(b,a%b)
I am new to python, i hope this has something to do with spaces. Can anyone help me out.enter image description here Also attached the image. Thanks
def gcd(a,b):
if b == 0:
return a
elif a < b:
return gcd(b,a)
else:
return gcd(b,a%b)
I am new to python, i hope this has something to do with spaces. Can anyone help me out.enter image description here Also attached the image. Thanks
If you read the error, it says IndentationError, so you have problem with the indentation. You should know that python depends on indentation to define the scope of each block, so the content of a function must be indented, otherwise it won't be considered as the content of the function.
def gcd(a,b):
if b == 0:
return a
elif a < b:
return gcd(b,a)
else:
return gcd(b,a%b)
Function definitions also have a level of indentation to them, so it should look as follows:
def gcd(a,b):
if b == 0:
return a
elif a < b:
return gcd(b,a)
else:
return gcd(b,a%b)