1

As a beginner in python, I keep getting an indentation error but I am not sure why?

>>> gbp_interest = 0.5
>>>
>>> difference_between_pairs = us_interest - gbp_interest
>>> print(abs(difference_between_pairs))
0.3
>>>
>>> if abs(difference_between_pairs) > 0.1 :
... print(max(us_interest, gbp_interest))
  File "<stdin>", line 2
    print(max(us_interest, gbp_interest))
        ^
IndentationError: expected an indented block

Further, is there a reason python is sensitive to indentation (more so then other programming languages)?

  • You get an indentation error because your indentation is wrong, and it matters in Python because the designer decided it should. – jonrsharpe Nov 30 '21 at 23:17
  • 3
    Both these questions go back to some very, *very* fundamental Python concepts. If you truly don't have any inkling as to the answers to both of these, you need to go back and read some more fundamental literature on the language itself as it's very clear there are some severe gaps in your lexical understanding. Unfortunately, Stack Overflow isn't conducive to to hand-hold you through your fundamental learning - a simple Google search will yield millions of results which can guide you through these fundamental concepts from a base level (coming from no prior experience at all). – esqew Nov 30 '21 at 23:17
  • because the indentation in python is roughly equivalent to `{ }` in c-types languages to define scopes – Cid Nov 30 '21 at 23:20
  • Thanks guys for the comments, appreciate the help – thecodermode66 Dec 01 '21 at 12:14

1 Answers1

2

Indentation is, I would say, the key feature of python.

Indentation helps you define blocks of code. It is to python what { } usually are to some other programming languages.

Indent your print:

>>> if abs(difference_between_pairs) > 0.1 :
...     print(max(us_interest, gbp_interest))

Consider starting a tutorial, there are plenty of resources on the web. Example: https://docs.python.org/3/tutorial/index.html

Costin
  • 2,699
  • 5
  • 25
  • 43