Python Forum
SyntaxError: multiple statements found while compiling a single statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: multiple statements found while compiling a single statement
#1
This code works on Codecademy, but when I use it in Python I get an error message:
SyntaxError: multiple statements found while compiling a single statement
Why doesn't this code work in Python? Here is the code.
mylist = [2, 3, 4]
result = []
for number in mylist:
  result.append(number*2)
print result 
Reply
#2
Always post the error traceback in it's entirity and unmodified.
This code should run fine in python 2.7
in python 3, you have to modify the print statement to:
print(result)
.

FIY: indentation should be 4 spaces, as per PEP8.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create multiple/single csv file for each sql records mg24 6 1,322 Sep-29-2022, 08:06 AM
Last Post: buran
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Multiple Loop Statements in a Variable Dexty 1 1,175 May-23-2022, 08:53 AM
Last Post: bowlofred
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  How do you format Update statement with multiple conditions hammer 4 2,038 Dec-16-2021, 10:49 PM
Last Post: hammer
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,265 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,809 Oct-04-2021, 03:29 AM
Last Post: deanhystad
  Ploting single column with multiple category drunkenneo 1 1,946 May-26-2021, 04:51 PM
Last Post: jefsummers
  Compiling (PyInstaller issues) TheHolyPyGrenade 1 1,881 Apr-11-2021, 08:30 PM
Last Post: snippsat
  Inserting multiple rows in a single request. swaroop 2 2,851 Jan-11-2021, 01:34 PM
Last Post: swaroop

Forum Jump:

User Panel Messages

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