-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

3142 maple
  • 865
  • 2
  • 11
  • 27

2 Answers2

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)))
user3543300
  • 499
  • 2
  • 9
  • 27
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.

Nadia Cerezo
  • 602
  • 5
  • 12