• Register
0 votes
1.2k 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?

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.

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.

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.”

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.

11 5 2
3,890 points

Related questions

1 vote
1 answer 6 views
6 views
Problem: So as I am new to programming. therefore need expert opinion on this. Python multiple statements found while compiling a single statement.
asked Apr 20 PkGuy 23.5k points
0 votes
1 answer 14 views
14 views
Problem: Why is there this syntax error 'Multiple statements found while compiling a single statement' given when I run this code? Answer and help will be super appreciated for this python newbie here
asked May 2 jamuna1 30.2k points
0 votes
1 answer 17 views
17 views
Problem: Hi please help me with this error. Syntaxerror: unexpected eof while parsing python
asked Mar 20 PkGuy 23.5k points
0 votes
1 answer 18 views
18 views
Problem: I am getting error while running this part of the code. tried some of the existing solutions, none of them helped elec_and_weather = pd.read_csv(r'C:\HOUR.csv', parse_dates=True,index_col=0) # Add historic DEMAND to each X vector for i in ... 24 for k in range(n_hours_advance,n_hours_advance+n_hours_window): elec_and_weather['DEMAND_t-%i'% k] = np.zeros(len(elec_and_weather['DEMAND']))'
asked Feb 17 Mashhoodch 13k points
0 votes
1 answer 31 views
31 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 117 views
117 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
0 votes
1 answer 93 views
93 views
Problem: How to I Solve this: %matplotlib inline ^ syntaxerror: invalid syntax HELP! I need help understanding this: %matplotlib inline ^ syntaxerror: invalid syntax Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 3 Mashhoodch 13k points
1 vote
1 answer 290 views
290 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
1 answer 7 views
7 views
Problem: How can I fix this please ? Python class __name__
asked Mar 21 PkGuy 23.5k points