Home > Software design >  Why is program terminating after input() prompt?
Why is program terminating after input() prompt?

Time:06-04

After an input() prompt my program terminates instead of moving on to the while() loops proceeding it which are meant to be executed depending on the input (yes/no). The program terminates after the data_confirmation input prompt.

username_prompt = input("Enter your username: ")
line_space = '\n'
print(line_space)

if username_prompt == user1_username:

    print("Bootcamp date: "   user1_bootcamp_date)
    print("Bootcamp venue: "   user1_bootcamp_location)
    print("Bootcamp type: "   user1_bootcamp_type)
    print("Exposure: "   user1_xp)
    print(line_space)

    data_confirmation = input("Please confirm whether the information above is correct (yes/no): ")
    print(line_space)

    while data_confirmation.lower == "yes":
        print("Thank you!")
        break

    while data_confirmation.lower == "no":
        data_correction_prompt = input("Which information is incorrect (e.g Date): ")
        print(line_space)

        if data_correction_prompt.lower == "date":
            bootcamp_date_c = input("Enter the correct date (e.g 4 April): ")
            user1_bootcamp_date = bootcamp_date_c
            print(line_space)
            print("Thank you!")
    
        elif data_correction_prompt.lower == "venue":
            bootcamp_venue_c = input("Enter the correct venue (e.g Johannesburg): ")
            user1_bootcamp_location = bootcamp_venue_c
            print(line_space)
            print("Thank you!")
    
        elif data_correction_prompt.lower == "type":
            bootcamp_type_c = input("Enter the correct type (Physical/Virtual): ")
            user1_bootcamp_type = bootcamp_type_c
            print(line_space)
            print("Thank you!")
    
        elif data_correction_prompt.lower == "exposure":
            bootcamp_xp_c = input ("Enter your experiernce (e.g No prior experience/Prior experience): ")
            user1_xp = bootcamp_xp_c
            print(line_space)
            print("Thank you!")

        else:
            data_correction_prompt = input("Invalid input. Please state date/venue/type/exposure: ")
    
        break

CodePudding user response:

As @user2182349 mentioned, you have not shown us the declaration of the variable user1_username. Since the input is being compared with that, the while loop will only run if the username_prompt is equal to that value.

Perhaps you have forgotten to declare a variable and are comparing it to undefined?

Hope this helped :D

CodePudding user response:

lower is a function available to the string type. When you invoke data_confirmation.lower, you are not calling the lower function. Instead, you are referencing the function itself. Being a function, lower of course can never itself be equal to the strings "yes" or "no". To indicate you are actually calling the function, you must add parentheses: data_confirmation.lower().

  • Related