2017-03-08 8 views
-1

EDIT:この質問は、Pythonの学習プロセスの初めに聞かれました。 Syntax Errorはpythons IDLEによって生成され、トラックバックはありません。これは、人々が完全な誤りを求めたときの問題と混乱の主な原因でした。whileループの終了時にエラーが発生する

私は簡単なメモリコールプログラムに取り組んでいます。私は100%誰も助けることができる場合、なぜ私は構文エラーを取得し続けている確信していません。

注:エラーは「構文エラー」のみでした。エラーが表示されるその他の情報はありませんでした。

program = Falseは、プログラムコードの最後にエラーが表示されています。私は印刷物や何かの後にそれを置くことを許されていませんか?

私はPythonとプログラミング全般について非常に新しいです。あなたが解決策を持っているならば、私が間違っていたことを説明してください。

#################################################################################### 
''' Goal = quick access list of notes that I can add to or remove from as needed.''' 
''' Note: this script is designed for python 3.2+ check converted elements ''' 
#################################################################################### 

notes = { 
    'ban': 'BAN: is the account number.', 
    'bdt': 'testing derp' 
    } 

program = True 
active = False 

def note_finder(word): 

    while active == True: 
     print ('Type one of the following keywords','\n','ban','\n','test','\n','test2','\n', 'Or type exit to close') 
     choice2 = input('--> ').lower() 
     if choice2 == 'exit': 
      print ('Exiting Function') 
      active = False 
      program = True 
     elif choice2 in notes: 
     print (notes[choice2]) 
     else: 
     print ("Not a Keyword") 

while program == True: 
    print ('Type one of the following options:','\n','1','\n','2','\n','3') 
    choice1 = int(input('--> ')) 
    if choice1 < 1 or choice1 > 3: 
     print ("Not an option") 
    else: 
     print (note_finder(input('--->')) 
     program = False 
     active = True 
+2

前の行にカッコが一致していません。 – ForceBru

+0

なぜこの質問が投票されたのか分かりません。これは正当な質問でした。私が誰かのためにコードを書くように頼んでいたのと同じではありません。 –

+0

質問に*完全な*構文エラーメッセージが含まれていますので、より簡単にお手伝いします。さらに、エラーメッセージは、あなたが問題を解決するのに役立つかもしれません。 –

答えて

1

印刷ラインの最後に括弧がありません。

お持ち:

print (note_finder(input('--->')) 

を、それがあるべき:

else: 
    print (note_finder(input('--->'))) 
    program = False 
    active = True 
1

エラー・コードが指定されていないとして、私ははっきりつのエラーを見ることができます:

while program == True: 
    print ('Type one of the following options:','\n','1','\n','2','\n','3') 
    choice1 = int(input('--> ')) 
    if choice1 < 1 or choice1 > 3: 
     print ("Not an option") 
    else: 
     print (note_finder(input('--->')) # mismatched parentheses(add a ')') 
     program = False 
     active = True 
0

それがあれば役立つだろうあなたはエラーが何であるか教えてくれました。エラーが何かを確認するには、プログラムを対話モードで実行するのが最も簡単な方法です。それはあなたに伝えます:

File "...", line 19 
    print (notes[choice2]) 
     ^
IndentationError: expected an indented block 

これはかなり明確です。これは、そのコード行が以前に来たものよりもインデントされるべきであることを意味しますが、そうではありません。

各コロン:の後には、インデントされたブロックが必要です。例えば

elif choice2 in notes: 
print (notes[choice2]) 

elif choice2 in notes: 
    print (notes[choice2]) 
0

あるべき構文エラーと元の問題は、私のprint文の「)」が不足しているためでした。

「Karan Nagpal」のおかげで、&「Agile Jedi」は素早く対応します。

しかしそれが修正された後、私はいくつかの他の問題に遭遇しました。

私は他の問題を修正し、コードを少し変更して、問題なく何をしようとしていたかを正確に行いました。

興味があればここに新しい作業コードがあります。

#################################################################################### 
''' Goal = quick access list of notes that I can add to or remove from as needed.''' 
''' Note: this script is designed for python 3.2+ check converted elements ''' 
#################################################################################### 

notes = { 
    'ban': 'BAN: is the account number.', 
    'bdt': 'testing derp' 
    } 

switch = True 

def note_finder(word): 
     print ('Type one of the following keywords','\n','ban','\n','test','\n','test2','\n', 'Or type exit to close') 
     choice2 = input('--> ').lower() 
     if choice2 == 'exit': 
      print ('Exiting Function') 
      switch = True 
     elif choice2 in notes: 
      print (notes[choice2]) 
     else: 
      print ("Not a Keyword") 

while switch == True: 
    print ('Type one of the following options:','\n','1','\n','No other options at this time.') 
    choice1 = int(input('--> ')) 
    if choice1 < 1 or choice1 > 1: 
     print ("Not an option") 
    else: 
     switch = False 
     note_finder(input) 
関連する問題