Programmers learn & share
0 votes
183 views

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?

by (3.9k points)   | 183 views

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.

OR

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.

by (36.1k 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.”

Reason:

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

Example:

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.

Solution:

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.

Note:

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.

by (2.7k points)  
2,221 questions
2,697 answers
59 comments
241 users