Python Forum
Python Shell 3.9.0 - Issue with indentation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Shell 3.9.0 - Issue with indentation
#11
NEITHER of the 3 snippets you show above can possibly work on ANY python version/iterpreter! They have the same problem. The indentation of line 3 is INCONSISTENT with the rest of the indentation of the code. In addition the indentation of the last line in the third snippet is off too. The error you get is pretty clear too.
for i in [12, 16, 17, 24, 29]:
    if i % 2 == 1: # 4 spaces indentation = 1 level deep
       break # 7 spaces indentation, when it has to be 8 spaces to represent 2 levels deep indentation
    print(i) # 4 spaces indentation = 1 level deep
  
print("done") 
this will work

for i in [12, 16, 17, 24, 29]:
    if i % 2 == 1: # 4 spaces indentation = 1 level deep
        break # 8 spaces indentation = 2 levels deep indentation
    print(i) # 4 spaces indentation = 1 level deep
  
print("done") 
If you are not reading and following what you have been told or what the error says, no one can help you though.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Python Shell 3.9.0 - Issue with indentation - by buran - Oct-26-2020, 05:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,555 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Launch Python IDLE Shell from terminal Pavel_47 5 1,391 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  batch file for running python scipt in Windows shell MaartenRo 2 2,026 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  How to make a Python program run in a dos shell (cmd) Pedroski55 2 2,420 Nov-09-2020, 10:17 AM
Last Post: DeaD_EyE
  Python "Terminal" vs "Shell" SectionProperties 2 2,740 Apr-10-2020, 08:36 AM
Last Post: SectionProperties
  looping and indentation issue ameydiwanji 3 2,528 Jul-01-2019, 10:53 AM
Last Post: perfringo
  python shell teelado 1 21,022 Jun-13-2019, 01:49 AM
Last Post: Larz60+
  Is it possible to have my python shell change the backgrounds colour? OTO1012 2 3,891 Mar-07-2019, 09:32 PM
Last Post: woooee
  Indentation error in Python code ErnestTBass 5 3,670 Feb-28-2019, 04:26 PM
Last Post: samsonite
  running python script from shell invoked with os.system("x-terminal-emulator -e /bin/ markhaus 2 3,181 Feb-21-2019, 11:55 PM
Last Post: markhaus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020