Which function to use for making user input strings case insensitive?
correctAnswer = "London"
userGuess = input("What is the capital of Great Britain?: ")
if userGuess == "London":
print("Correct!")
else:
print("Wrong")
I have tried the following functions after the string:
.lower()
.capitalize()
.casefold()
The output is still 'wrong' although the answer should be correct when input is:
- london
- lOndoN
- loNDON
And so on..
In your string comparison, the correct answer itself had the first letter capitalized.
correctAnswer = "london"
userGuess = input("What is the capital of Great Britain?: ").lower()
if userGuess == correctAnswer:
print("Correct!")
else:
print("Wrong")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With