0

im creating an option button that can expand into multiple options to narrow down what the user wants to search, i havent found a function similar to what i want to achieve and tried using while and if-else to attempt it

it worked for the first layer of questions but when i tried to add more if-else within the option it keeps showing expected indented block for the else line.

Has anyone found a workaround or am i misunderstanding if-else statements?

load_titanic("titanic.csv")
print("Welcome to the Titanic Dataset Explorer")
option = "A"

while option.upper() != "Q":
    print()
    print("Select an option")
    print("(1) Display number of families that embarked from each port")
    # (1) cherboug: , queenstown: , southampton:
    print("(2) Display families boat status")
    # (2) display no. fam same boat, no. fam diff boat, no. of fam no boat

    print("(Q) Quit")
    option = input("> ")
    print()

    # add additional option as terminal cannot load all
    if option == "1":
        option2 = "B"
        while option2.upper() != "Return":
            print()
            print("Select Display Method")
            print("(1)Display Only Cherboug Passengers")
            print("(2)Display Only Queenstown Passengers")
            print("(3)Display Only Southampton Passengers")
            print("(4)Display All")
            print("(R)Return")
            option2 = input("> ")
            print()

            if option2 == "1":
                display_fam_boat_stat()

            elif option2 == "2":
                display_fam_boat_stat()

            elif option2 == "3":
                display_fam_boat_stat()

            elif option2 == "4":
                display_fam_embkall()

            elif option2.upper() == "R":
            
            else:                               <Expected indented block
                print("Invalid option")
                print()

        

    elif option == "2":
        display_fam_boat_stat()

    elif option.upper() == "Q":
        print("Thank you for using the Titanic Dataset Explorer")
    else:
        print("Invalid option")
        print()
  • `elif option2.upper() == "R":` ... Then what? You need to put something there. I've closed your question under an existing one that covers your options. Just search `IndentationError: expected an indented block` cause it's quite lengthy. – wjandrea Jul 10 '23 at 18:16
  • BTW, `option2.upper()` will never equal `"Return"` since `"Return"` is not uppercase – wjandrea Jul 10 '23 at 18:18
  • BTW, welcome to Stack Overflow! Check out the [tour], and [ask] for tips like making a [mre]. – wjandrea Jul 10 '23 at 18:18
  • o tq! i was scratching my head on why it didnt work but all the lines made me miss out on that one mistake... not used to seeing so much and still annoyed about how small mistakes are impossible to find, like using the wrong bracket on one line == – Joshua Tang Jul 13 '23 at 13:52

0 Answers0