Can't get string user input working (Python)

Question:

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'.")
Asked By: Peter

||

Answers:

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'.")
Answered By: Deepak Tripathi

You just need one amendment to this line:

Instead of

answer = answer.islower()

Change to

answer = answer.lower()

Answered By: nuttychan
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.