louis lau
louis lau

Reputation: 327

syntax error when taking input in python?

I'm new to python. Could anyone suggest what goes wrong with this input command. I'm running this code in python 3.7.0 from anaconda

def annotation_tool(path):
final_results = []
nlp = spacy.load("en_core_web_sm")
if path != '':
    file_text = open(path, "r").read()
    nlp_file_doc = nlp(file_text)
    sentences = list(nlp_file_doc.sents)
    for i in sentences:
        print("--------- Next sentence is %s ---------".format(i))
        print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp))
        num_candidates = int(input("Enter number of candidates"))
        pair = []
        for x in range(0, num_candidates):
            candidates = input("--------- Enter candidates e.g. computer, good ---------")
            polarity = input("--------- Enter polarity of above candidates (pos/neg/neu) ---------")
            dict = {candidates: polarity}
            pair.append(dict)
        result = {"sentence": i, "candidates": pair}
        final_results.append(result)
        is_continue = input("--------- Continue with annotation y/n? ---------")
        if is_continue == 'n':
            break
return final_results

Here is syntax error:

File "test.py", line 128
num_candidates = int(input("Enter number of 
candidates"))
SyntaxError: invalid syntax

Upvotes: -1

Views: 826

Answers (1)

RiskyMick
RiskyMick

Reputation: 151

The error is from the line above:

print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp))

missing a closing parenthesis on the print statement

print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp)))

Upvotes: 4

Related Questions