if语句中的if语句

时间:2016-08-17 02:57:02

标签: python

这是我的功课,我坚持让代码成为一个跟进问题,就像这里的代码一样,我之后尝试插入一个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)

2 个答案:

答案 0 :(得分:4)

你有一个额外的缩进。只需删除额外的缩进级别:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests;
use App\User as User;
use Hash;

class CheckLoginController extends Controller
{
    public function check(Request $request)
    {
        if( $request->ajax() ) :
            $user = User::where('email', '=', $_POST['email'])->first();
            if( $user ) :
                //check password
                if( Hash::check($_POST['password'], $user->password) ) :
                    Auth::login($user);
                    echo "success";
                else :
                    echo "Invalid username/password";
                endif;
            endif;
        endif;
    }   
}

答案 1 :(得分: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:

相关问题