Posts: 6
Threads: 1
Joined: Oct 2020
Oct-25-2020, 03:51 AM
(This post was last modified: Oct-25-2020, 03:51 AM by Earis.)
https://www.ppaste.org/ZlGieSKbc
The above code works fine on any other interpreter(12,16,done) but when I use the python shell 3.9.0 I get SyntaxError: unindent does not match any outer indentation level.
Tried different approaches but nothing worked.
Using any other interpreter is fine but I want to know why it doesn't work on Python Shell 3.9.0 and how to fix it.
Any ideas ?
Posts: 8,165
Threads: 160
Joined: Sep 2016
Oct-25-2020, 05:51 AM
(This post was last modified: Oct-25-2020, 05:51 AM by buran.)
Please, post your code here - copy/paste as text in python tags. What you show on the picture has problems with the indentation as well as the 2 print functions on the last line. This code cannot run on any python.
If this cross-posted as implied by the image, you should add link to the other medium too.
Posts: 7,324
Threads: 123
Joined: Sep 2016
Look at this image.
The only way you can get unindent does not match any outer indentation level with that code if fix last line.
Are if run code in IDLE Python shell >>> ,and not as New File as image.
Correct code,always 4-space indentation in Python.
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") Output: 17
done
Posts: 1,583
Threads: 3
Joined: Mar 2020
The code in that paste doesn't generate an indentation error, but a syntax error from having the two prints on the same line.
I don't see anything here that should be different between any version of python 3, either 3.9 or earlier.
Posts: 6
Threads: 1
Joined: Oct 2020
Oct-26-2020, 04:12 AM
(This post was last modified: Oct-26-2020, 04:22 AM by Earis.)
https://www.ppaste.org/lPOwHRon3
My apologies for any confusion. The correct code is the above and it does not run in Python Shell.
Posts: 6,809
Threads: 20
Joined: Feb 2020
Oct-26-2020, 04:22 AM
(This post was last modified: Oct-26-2020, 04:30 AM by deanhystad.)
Stop posting links. Paste your code directly into your post and surround it with python tags. Like this:
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") You should not be typing programs in the shell. Type programs in a file and run the file. If you have to type code in the shell you need to add empty lines at the end of a compound statement so Python knows when it reached the end of a statement
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") Also note that you cannot cut and paste multiple statements in the shell. The shell is for one statement at a time. This is one statement:
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i) And this is another.
print("done") You need to press the enter key to execute the first statement before you start entering the second.
Posts: 6
Threads: 1
Joined: Oct 2020
Not it doesn't.
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") # For this Line I get in Python Shell 3.9.0 SyntaxError: unindent does not match any outer indentation level
Posts: 8,165
Threads: 160
Joined: Sep 2016
The indentation of line 3 is just 3 spaces. It should be 4.
Posts: 1,583
Threads: 3
Joined: Mar 2020
Maybe you have some unprintable characters in your file. What OS are you on? If you're on linux, show the output of od -c <filename> .
Posts: 6
Threads: 1
Joined: Oct 2020
I am using Windows 10.
Tried in the pas all the above mentioned methods.
Works giving the result 12,16.
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i) Doesn't work giving SyntaxError: unindent does not match any outer indentation level
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") Also SyntaxError: unindent does not match any outer indentation level
for i in [12, 16, 17, 24, 29]:
if i % 2 == 1:
break
print(i)
print("done") In conclusion am I to assume that the above code will never work on python Shell 3.9.0 ?
If yes why ?
|