-1
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

nano
  • 17
  • 1
  • 5
  • 5
    Does this answer your question? [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – Willy satrio nugroho Aug 09 '20 at 03:44

2 Answers2

0

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)
AnaS Kayed
  • 422
  • 3
  • 9
  • The error says `IndentationError` but the full message is not consistent with the code they have posted. It is clear that at whatever time they got that message, the `if` statement *was* indeed indented (or it would have complained about that), but the unindent on `elif` was to the wrong column. One can only speculate about exactly what their code did look like, although I've shown a possible example in my answer. I am guessing that the code which they finally posted was the result of a failed attempt to fix the original error. –  Aug 08 '20 at 09:42
0

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)
johannesack
  • 660
  • 3
  • 19