An IndentationError error occurs.

Asked 2 years ago, Updated 2 years ago, 58 views

def quotient(a, b):
    if b == 1:
        return a
    else:
        if a > b:
           a = a - b
           p = p + 1
          else:
              return p

        return quotient(a, b)

If you do this, the indentationError: unindent does not match any outer indentation level I get this error How shall I do it?

python indentation

2022-09-22 15:06

1 Answers

def quotient(a, b):
    if b == 1:
        return a
    else:
        if a > b:
           a = a - b
           p = p + 1
        else:
           return p

        return quotient(a, b)

Python separates blocks by indentation. If ~ else must be indented in front of the same size.

I think it would be better to have a habit of indent with tabs or indent with 2 spaces (or 4 spaces) at a time you indent with tabs.


2022-09-22 15:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.