• Register
0 votes

Problem :

Currently I am using the Python 3.3 and I have only entered these 3 below lines:

import sklearn as sk
import numpy as np
import matplotlib.pyplot as plt

But I am facing below error:

“SyntaxError: multiple statements found while compiling a single statement”

What is wrong with my Python code?

7 5 2
3,870 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

In the shell script, you can not execute more than the one statement at the same time as shown below:

>>> a = 5
b = 6
“SyntaxError: multiple statements found while compiling a single statement”


So you will need to execute them one by one as shown below :

>>> a = 5
>>> b = 6

Whenever you see the multiple statements are being declared, that clearly means you're seeing the script, and it will be executed later. But in your interactive interpreter, you can not do more than the one statement at a time.


I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started. If anyone faces the same question then the simple solution which I found was to download the Idlex and use its IDLE version, which allows the multiple lines.

9 7 4
38,600 points
0 votes

When the user write more than one statements in a shell then he can encounter the error’

“SyntaxError: Multiple statements found while compiling a single statement.”


The reason behind this error that you can not execute more than one statement in a shell.


Look at the following example to understand this error;

>>> print (“My first python code”)

print(“Easier than expected”)

SyntaxError: multiple statements found while compiling a single statement.

What is the syntax error?

A syntax error is an error that occurs that there is something wrong with the code format.


To solve this error you have to write a single statement at a time in a shell. The user needs to execute one by one like;

>>> print(“My first python code”)

My first python code

>>> print(“Easier than expected”)

Easier than expected.

When you see multiple statements are being declared, that means you are seeing a script which will be executed later. But in the interactive interpreter, you cannot do more than one statement at one time.


To open the python shell from IDLE go to File > New File. Type your statements into the shell and save it. The user can name it whatever he wants but make sure that it has .py extension at the end. The from the same shell windows go Run > Run module. Now you can see results.

11 5 2
3,890 points

Related questions

0 votes
1 answer 18 views
Task: Read an integer N . For all non-negative integers i<N , print i2. if __name__ == '__main__': n = int(input()) if (n<=0) and (n>=20): print("Exit") else: for(i=0,i<=n,i++): print(i*i) I am getting below error File "solution.py", line 6 for(i=0,i<=n,i++): ^ SyntaxError: invalid syntax Exit Status 255
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 31 views
Hello house, I would like to know how to solve this Python SyntaxError: Non-ASCII character '\xe2' in file. Thanks
asked Oct 23, 2020 psandprop 2.4k points
1 vote
1 answer 177 views
Problem: Hello programmers, I hope you all are doing good in this hard time of Covid-19. I am under lockdown inside my house for more than two months. I was being mad. I decided to learn something new in these days. Therefore, I come to an end with the decision of ... mine that don&rsquo;t work var = 123 123 = roy print(var) print(123) Please, review the codes and help this beginner to walk ahead.
asked May 31, 2020 adamSw 11.3k points
0 votes
2 answers 77 views
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains print("Hello.")), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have ... but when I do so I get this: File "<stdin>", line 1 python test.py ^ SyntaxError: invalid syntax What is wrong? Thanks in advance!
asked Oct 25, 2020 psandprop 2.4k points
0 votes
2 answers 388 views
Problem: Hello guys, I am running this code in visual code but dont know why the error ic coming can you please check the error of if__name__ ==__main__invalid syntax. def main(): generateRandomNumbers() def generateRandomNumbers(): print ('Test') si_ze = 0 nameLength=0 ... == "__main__" main() Getting Syntax error if name == main ^ SyntaxError: invalid syntax Process finished with exit code 1
asked Jun 9, 2020 Gavin 15.3k points
1 vote
1 answer 36 views
Problem: Hello guys, While solving basic condition problem in python I am trying to implement the below logic but don't know python is throwing error, the invalid syntax for no reason,below is the code. day = int(input("Enter the day of week:")) vacation = (input("Enter is vacation? [True| ... 00") else: if day == 0 or day == 6: print("Alarm is off") elif: print("10:00") Dont know what is wrong.
asked Jun 7, 2020 Gavin 15.3k points
2 votes
2 answers 284 views
Problem: I have a simple python program I wrote recently. But unfortunately, I can&rsquo;t compile and run my program. It shows me an error &ldquo;syntaxerror: keyword can't be an expression&rdquo; Where I am being wrong in my program? Any idea? The snippet is attached below: name = input("Please ... a Gentleman!") else: print(name + " I don't know him and " + name = " Who is he? ") Thanks, guys.
asked Mar 11, 2020 Gavin 15.3k points
0 votes
1 answer 7 views
Problem: I am trying to define a function to make the perimeter of a rectangle. Here is the code: width = input() height = input() def rectanglePerimeter(width, height): return ((width + height)*2) print(rectanglePerimeter(width, height)) I think I haven't left any arguments opened or anything like that.
asked Jan 11 Mashhoodch 6.3k points
0 votes
1 answer 15 views
Problem: Hello kodlogs, I have a doubt in python, I am new in python programming language and want to know that about the &ldquo;if&rdquo; concept that can we use it inside the while loop or in other loop is there any restriction in using it ?. Though its a easy question but wondering how can we achieved it and what are the various possibilities to do it in the python language.
asked Jun 15, 2020 Gavin 15.3k points