我无法理解Python 3.7中的语法错误

时间:2019-11-27 07:57:37

标签: python-3.x if-statement syntax syntax-error

我正在以初学者的身份学习Python(通过Spyder运行python 3.7),并且遇到了无法解释的语法错误。我已经根据几个示例和有效的代码进行了检查,但我仍然无法理解我在语法方面的错误。该错误发生在包含代码的行上-如果yn =='Y':

import json     
import difflib   
from difflib import get_close_matches

content = json.load(open('data.json', 'r'))

def getDefinition(word):  

    word = word.lower()  
    if word in content:
        return content[word]
    elif len(get_close_matches(word, content.keys(), cutoff=0.8)) > 0:
        yn = input('Did you mean %s? Enter Y if yes, N if no.' % (get_close_matches(word, content.keys(), cutoff=0.8)[0])

语法错误出现在下一行

        if yn == 'Y':
            return get_close_matches(word, content.keys(), cutoff=0.8)[0]
        elif yn == 'N':
            return 'Word does not exist.'
        else:
            return 'Did not understand entry.'
    else:
        return 'Word does not exist.'

word = input('Enter word: ')

output = getDefinition(word)

if type(output) == list:
    for item in output:
        print(item)
else:
    print(output)

1 个答案:

答案 0 :(得分:0)

public class EstimateStatus
{
    public int Id { get; set; }
    public string Name { get; set; }

    public int? ParentId { get; set; }

    public EstimateStatus ParentStatuses { get; set; }
    public virtual ICollection<EstimateStatus> SubsequentStatuses { get; set; }
}

public class TestDbContext:DbContext
{
    public TestDbContext (DbContextOptions<TestDbContext> options):base(options)
    { }

    public DbSet<EstimateStatus> EstimateStatuse { get; set; }


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<EstimateStatus>()
            .HasMany(e => e.SubsequentStatuses)
            .WithOne(s => s.ParentStatuses)
            .HasForeignKey(e => e.ParentId);
    }
}