Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

elif statement unreached in Python script

In the following code, the if statement is reached and runs fine. The elif statement however seems to have no effect. When the script is run, when the conditions for the elif statement are met, nothing happens and when I press return button twice the script just keeps going skipping the elif statement altogether.

My code:

            print("If you want to name this window press 1, if you want to describe it press 2")
            if input() == "1":
                print("Please enter this window's title:")
                current_window_title = input()
                print("Do you also want to describe this window? P.S: You can do this later.)")
                if input().lower() == "yes":
                    print("Please enter this window's description:")
                    current_window_description = input()
                else:
                    current_window_description = "None"
            elif input() == "2":
                print("Please enter this window's description:")
                current_window_description = input()
                print("Do you also want to give this window a title? P.S: You can do this later.")
                if input().lower() == "yes":
                    print("Please enter this window's title:")
                    current_window_title = input()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because you got an input from the user and in the same range if and this amount of input is not available in elif you can do these two things and it will work properly:

print("If you want to name this window press 1, if you want to describe it press 2")
inp = input()
if inp == "1":
    print("Please enter this window's title:")
    current_window_title = input()
    print("Do you also want to describe this window? P.S: You can do this later.)")
    if input().lower() == "yes":
        print("Please enter this window's description:")
        current_window_description = input()
    else:
        current_window_description = "None"
elif inp == "2":
    print("Please enter this window's description:")
    current_window_description = input()
    print("Do you also want to give this window a title? P.S: You can do this later.")
    if input().lower() == "yes":
        print("Please enter this window's title:")
        current_window_title = input()

or :

print("If you want to name this window press 1, if you want to describe it press 2")
if input() == "1":
    print("Please enter this window's title:")
    current_window_title = input()
    print("Do you also want to describe this window? P.S: You can do this later.)")
    if input().lower() == "yes":
        print("Please enter this window's description:")
        current_window_description = input()
    else:
        current_window_description = "None"
if input() == "2":
    print("Please enter this window's description:")
    current_window_description = input()
    print("Do you also want to give this window a title? P.S: You can do this later.")
    if input().lower() == "yes":
        print("Please enter this window's title:")
        current_window_title = input()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading