-5

このコード:

def viewdetails():
    os.system('cls')
    print "|__________________________________________|"
    print "|----------------View Details--------------|"
    print "|------------------------------------------|"
    print "|1 - Search with Customer ID               |"
    print "|2 - Search with Telephone number          |"
    print "|------------------------------------------|"
    choice = raw_input("|Choice: ")
    if choice == "1":
        while True:
            IDSearch = raw_input("|What is their ID? : ")
            conn = sqlite3.connect('SADS.db')
            cur = conn.cursor()
            cur.execute("SELECT * FROM customers WHERE CustID = (?)",(IDSearch,))
            row = cur.fetchone()
            if row[0] != IDSearch:
                print "|------------------------------------------|"
                print "|          Invalid ID, Try again!          |"
                print "|------------------------------------------|"
            else:
                break
        CustID = row[0]
        print "|------------------------------------------|"
        print "|Customer ID : " , row[0]
        print "|Forename : " , row[1]
        print "|Surname : " , row[2]
        print "|Address Line 1 : " , row[3]
        print "|Address Line 2 : " , row[4]
        print "|City : " , row[5]
        print "|Postcode : " , row[6]
        print "|Telephone number : " , row[7]
        print "|E-Mail : " , row[8]
        while True:
            print '|Do you want to see what seats', row[1], 'has booked?|'
            choice = raw_input("|Y/N: ")
            if choice == 'Y':
                cur.execute("SELECT * FROM seats WHERE CustID = (?)", (CustID,))
                rowseat = cur.fetchone()
                if rowseat:
                    print "|Seats booked:" , rowseat[0]
                    print "|------------------------------------------|"
                    break
                else:
                    print "|" , row[1] , "Hasnt booked any seats."
                    break
    print(" ")
    print "|------------------------------------------|"
    print("|Please select an option:                  |")
    print("|1 - Return to menu                        |")
    print("|2 - Book seats                            |")
    print("|3 - Edit details                          |")
    choice = raw_input("|Please put choice here : ")
    print "|------------------------------------------|"
    elif choice == "2":
        while True:
            IDSearch = raw_input("|What is their ID? : ")
            conn = sqlite3.connect('SADS.db')
            cur = conn.cursor()
            cur.execute("SELECT * FROM customers WHERE CustID = (?)",(IDSearch,))
            row = cur.fetchone()
            if row[0] != IDSearch:
                print "|------------------------------------------|"
                print "|          Invalid ID, Try again!          |"
                print "|------------------------------------------|"
            else:
                break
        CustID = row[0]
        print "|------------------------------------------|"
        print "|Customer ID : " , row[0]
        print "|Forename : " , row[1]
        print "|Surname : " , row[2]
        print "|Address Line 1 : " , row[3]
        print "|Address Line 2 : " , row[4]
        print "|City : " , row[5]
        print "|Postcode : " , row[6]
        print "|Telephone number : " , row[7]
        print "|E-Mail : " , row[8]
        while True:
            print '|Do you want to see what seats', row[1], 'has booked?|'
            choice = raw_input("|Y/N: ")
            if choice == 'Y':
                cur.execute("SELECT * FROM seats WHERE CustID = (?)", (CustID,))
                rowseat = cur.fetchone()
                if rowseat:
                    print "|Seats booked:" , rowseat[0]
                    print "|------------------------------------------|"
                    break
                else:
                    print "|" , row[1] , "Hasnt booked any seats."
                    break
    print(" ")
    print "|------------------------------------------|"
    print("|Please select an option:                  |")
    print("|1 - Return to menu                        |")
    print("|2 - Book seats                            |")
    print("|3 - Edit details                          |")
    choice = raw_input("|Please put choice here : ")
    print "|------------------------------------------|"
    print(" ")
    print "|------------------------------------------|"
    print("|Please select an option:                  |")
    print("|1 - Return to menu                        |")
    print("|2 - Book seats                            |")
    print("|3 - Edit details                          |")
    choice = raw_input("|Please put choice here : ")
    print "|------------------------------------------|"
    if choice == "1":
        mainprogram()
    elif choice == "2":
        availablity()
    elif choice == "3":
        editdetails()
    os.system('cls')

viewdetails()

http://pastebin.com/X62jRLiL

elifステートメントを取得することはelif choice == "2":明らかに無効な構文ですが、elif choice == "1":動作し、次のコードは互いに正確に複製されていますか?

4

2 に答える 2

3

Pythonコードは適切にインデントする必要があります。

それ以外の場合は無効です。

これはおそらくPythonについて最初に学ぶことです(「ThinkinginPython」などの本を入手してください)。同時に、最も批判的なこと(少なくとも非ユーザーによる)。

有効なコード例:

if a == "1":
    echo "Apples"
elif b == "2":
    echo "Bananas"

インデントエラーによる無効なコード:

if a == "1":
echo "Apples"
elif b == "2":
    echo "Bananas"
于 2013-02-21T23:04:47.240 に答える
1

タブとスペースを混在させています。そうしないでください。次のようにスクリプトを実行します。

python -tt yourscript.py

どこを見つけるために。すべてのタブをスペースに置き換え、インデントにスペースのみを使用するようにエディターを構成します。

于 2013-02-21T23:09:16.163 に答える