语法错误,没有明显原因,怎么来的? (Python 3)

时间:2017-11-29 17:59:53

标签: python python-3.x debugging

以下程序是脱机代码生成器的代码段。程序应生成所需强度的密码。在调试时,问题在第10行突出显示为语法错误,在进一步测试程序时,确认了这一点。

有没有人知道为什么我会收到语法错误?

import string
menu="Y"
wordchoice="Y"
easywords=[]

CharactersList=list(string.ascii_uppercase)
LowerList=list(string.ascii_lowercase)
SymbolsList=list(string.punctuation)

NewList=(LowerList+SymbolsList+CharactersList)

while menu == "Y":
    strength=int(input("How strong would you like your password? \n1. Weak \n2. Medium \n3. Strong"))

numchoice=0

if strength == 1:
    while wordchoice=="Y":
        numchoice=numchoice+1
        EasyPass=input("Pick your word: ")
        easywords.append(EasyPass)
        wordchoice=input("Continue? (Y/N): ")
firstWord=(random.choice(easywords))
secondWord=(random.choice(easywords))
print ("\n\n",firstWord,secondWord)
menu=input("Return to main menu? (Y/N): ")

elif strength == 2:

    Letter1=(random.choice(NewList))
    Letter2=(random.choice(NewList))
    Letter3=(random.choice(NewList))
    Letter4=(random.choice(NewList))
    Letter5=(random.choice(NewList))
    Letter6=(random.choice(NewList))
    Letter7=(random.choice(NewList))
    Letter8=(random.choice(NewList))
    Letter9=(random.choice(NewList))

    print(Letter1,Letter2,Letter3,Letter4,Letter5,Letter6,Letter7,Letter8,Letter9)
    menu=input("\n\nCreate another password? (y/N): ")

1 个答案:

答案 0 :(得分:0)

因为每个elif需要与if配对。您不能将const todoType = new GraphQLObjectType({ name: 'todo', description: 'todo item', fields: () => ({ itemId: { type: (GraphQLInt), description: 'The id of the todo.', }, item: { type: GraphQLString, description: 'The name of the todo.', }, completed: { type: GraphQLBoolean, description: 'Completed todo? ' } }) }); 语句与其elif分开。

要解决此问题,请重新组织代码并确保if直接跟在elif之后。