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

Can't get string user input working (Python)

I’ve searched the web and this site and been messing around all day, trying 100 ways to get this simple little program working. I’m practicing endless While loops and string user inputs. Can anyone explain what I’m doing wrong? Thank you!

while True:
    print("This is the start.")

    answer = input("Would you like to continue? (Y/N) ")
    answer = answer.islower()
    if answer == "n":
        print("Ok thank you and goodbye.")
        break
    elif answer == "y":
        print("Ok, let's start again.")
    else:
        print("You need to input a 'y' or an 'n'.")

>Solution :

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

your code has one thing wrong answer.islower() will return boolean values True or False but you want to convert it into lower values so correct method will be answer.lower()

while True:
    print("This is the start.")

    answer = input("Would you like to continue? (Y/N) ")
    answer = answer.lower() # change from islower() to lower()
    if answer == "n":
        print("Ok thank you and goodbye.")
        break
    elif answer == "y":
        print("Ok, let's start again.")
    else:
        print("You need to input a 'y' or an 'n'.")
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