2016-08-17 22 views
1

これは私の宿題であり、コードを作成することに固執しています。ここのコードのように、このコードのようにifステートメントを挿入しようとしましたが、インセントエラー。ここでifステートメント内のifステートメント

は私のコードは、これまでのところ、次のとおりです。

Choice = input("Hello! Do you want to buy or sell snakes? Please enter (b) or (s) :") 
if Choice == "b": 
    buySnake = input ("What snake do you want to buy? We are selling python, kingsnake, rattlesnake, deathadder, cobra, mamba, viper and gartersnake. Please choose one : ") 
     if buySnake == "python": 
      return (to be added) 
elif Choice == "s": 
    sellFsnakes(snakeList,name,amount) 
else: 
    print("Please try again.") 
    buyWsnakes(snakeList,name,amount) 
+0

予期せぬインデントがあると言えば、その行のインデントを見て、インデントされていないかどうかを検討してください。 – TigerhawkT3

答えて

4

あなたは余分なインデントを持っています。インデントの余分なレベルを削除してください:

Choice = input("Hello! Do you want to buy or sell snakes? Please enter (b) or (s) :") 
if Choice == "b": 
    buySnake = input ("What snake do you want to buy? We are selling python, kingsnake, rattlesnake, deathadder, cobra, mamba, viper and gartersnake. Please choose one : ") 
    if buySnake == "python": 
     return (to be added) 
elif Choice == "s": 
    sellFsnakes(snakeList,name,amount) 
else: 
    print("Please try again.") 
    buyWsnakes(snakeList,name,amount) 
0

インデントはPythonでコードブロックを作成する方法です。あなたのエラーはあなたが間違っていたことを正確に示しています

if condition: 
    # executes if condition is met 
    if internalCondition: 
     # executes if both condition and internalCondition is met 
elif otherCondition: 
    # executes if first statement didn't and otherCondition is met 
else: 
    # executes if nothing else executed 

あなたは余分な空白とif internalCondition:をインデント。

関連する問題