Home > OS >  Can't get string user input working (Python)
Can't get string user input working (Python)

Time:11-03

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'.")

CodePudding user response:

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'.")

CodePudding user response:

You just need one amendment to this line:

Instead of

answer = answer.islower()

Change to

answer = answer.lower()

  • Related