-2
>>> import sys
def prime(n):
    i=2
    isp=True;
    while(i<n):
        if(n%i==0):
            isp=False
            break
        n/=i
        i+=1
    if(n==1):
        isp=False
    return isp

while(True)
    x=input("num=")
    if x=="exit"
        sys.exit()
    print(prime(int(x))))

SyntaxError: multiple statements found while compiling a single statement

Why this code always "SyntaxError: multiple statements found while compiling a single statement"
in python 3.5.2

0

2 Answers 2

0

There were some syntax errors I found, I fixed them and the code ran fine for me. There was an extra ) in the last statement and you were missing a few : as well. Here's the updated version:

import sys

def prime(n):
    i=2
    isp=True;
    while(i<n):
        if(n%i==0):
            isp=False
            break
        n/=i
        i+=1
    if(n==1):
        isp=False
    return isp

while(True):
    x=input("num=")
    if x=="exit":
        sys.exit()
    print(prime(int(x)))
Sign up to request clarification or add additional context in comments.

Comments

0

You have multiple syntax errors in your code. There are no ; at the end of Python statements and every loop and conditional (so while and if) ends with a :. Also pay attention to parentheses, as you had an extra closing one in your print statement. Here I fixed the errors:

import sys
def prime(n):
    i=2
    isp=True
    while(i<n):
        if(n%i==0):
            isp=False
            break
        n/=i
        i+=1
    if(n==1):
        isp=False
    return isp

while(True):
    x=input("num=")
    if x=="exit":
        sys.exit()
    print(prime(int(x)))

Edit: I'd like to add that it was very easy to detect the syntax errors by using IDLE, the IDE that comes packaged with Python on Windows and that can easily be installed on Linux as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.