• 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

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 1
3,890 points

Related questions

1 vote
1 answer 116 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’t work var = 123 123 = roy print(var) print(123) Please, review the codes and help this beginner to walk ahead.
asked May 31 adamSw 11.3k points
0 votes
1 answer 171 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 Gavin 15.3k points
1 vote
1 answer 29 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 Gavin 15.3k points
2 votes
2 answers 166 views
Problem: I have a simple python program I wrote recently. But unfortunately, I can’t compile and run my program. It shows me an error “syntaxerror: keyword can't be an expression” 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 Gavin 15.3k points