2017-03-27 16 views
-6

声明なぜこのコードは構文エラーを生成しますか?

while True: 
    try: 
     continue_shopping=int(input("press 0 to stop shopping and print your reciept or press 1 to continue shopping")) 
    if continue_shopping !=0 and continue_shopping !=1: 
     print(" make sure you enter 0 or 1") 
    if continue_shopping !=1 
    keep_searching = False 
    if (continue_shopping == 0): 
     fileOne.close() 
     fileTwo = open("receipt.csv" , "r") 
     reader = csv.reader(fileTwo) 
     for row in reader: 
      if row != None: 
       print(row) 
    elif continue_shopping==1: 
     search_user_input() 
     quantity() 
quantity() 

5行目に無効な構文エラー赤で強調表示された「場合」、私はこれがあなたが忘れてしまった場合

+1

あなたが忘れてしまった「:」条件 – N0un

+1

の終わりにあなたは、構文エラーの次に 'てみ-if'句 –

+0

を使用することはできません:Pythonは、適切なインデントを必要とします。 try:ブロック内のすべてのコードには、任意のインデントが必要です。 keep_searching = Falseです。 – RvdK

答えて

1

である理由がわからない午前を生成する場合、私はこれで問題が発生しています":"条件の終わりに。

if continue_shopping !=1: 

EDIT - 第二の問題:もちろんあなたはまだ他の構文エラーがあります。 tryの後にexcept句が必要です。あなたは実際にそのような質問をする前にdocumentationを読む必要があります。

+0

5行目に無効な構文が表示される-_- – MeTooThanks

+0

これは問題ありませんか?真の中: 試し:! continue_shopping = INT(入力( "買い物を停止し、あなたの領収書を印刷したり、ショッピングを続けるために1を押して押し0")) = 0とcontinue_shoppingをcontinue_shopping場合= 1:! 印刷を除いて(」 continue_shopping!= 1の場合 場合: keep_searching = False if(continue_shopping == 0): fileOne.close() – MeTooThanks

+1

このコメントのインデントを読み取るにはどうすればよいですか? – N0un

0

if continue_shopping !=1:の終わりの構文ERORのセミコロンの次に(あなたのインデントを修正N0un

@によって
  • を指摘した。何のtry-かのブロックがありません。条件
  • があなたのIFSをリワーク場合は、インデントすべきです:彼らは、たとえば

あなたの試みの以外の欠落

  • エラーシナリオに通って落下:(ここではPythonのコンパイラを持っているので、構文エラーをむき出していない:)

    while True: 
        try: 
         continue_shopping=int(input("press 0 to stop shopping and print your reciept or press 1 to continue shopping")) 
         if continue_shopping !=0 and continue_shopping !=1: 
          print(" make sure you enter 0 or 1") 
          continue 
    
         if (continue_shopping == 0): 
          fileOne.close() 
          fileTwo = open("receipt.csv" , "r") 
          reader = csv.reader(fileTwo) 
          for row in reader: 
           if row != None: 
            print(row) 
         else: 
          search_user_input() 
          quantity() 
        except: 
         print("whups some exception") 
    
  • 関連する問題