Change Python if input is case insensitive

I am at school, and since we are quite young students, some of my "colleagues" do not understand what case sensitivity is. We are doing a quiz in Python. Here is the code:

score = 0 #this defines variable score, and sets it as zero
print("What is the capital of the UK?")
answer = input ()
if answer == "London":
    print("Well done")
    score = score + 1 #this increases score by one
else:
   print("Sorry the answer was London")
   print("What is the capital of France?")
answer = input ()
if answer == "Paris":
    print("Well done")
    score = score + 1 #this increases score by one
else:
    print("Sorry the answer was Paris")
    print("Your score was ",score)

      

They enter "london" for the answer instead of "London" and are still wrong. Any workaround?

+3


source to share


3 answers


You can use .upper()

or.lower()



if answer.lower() == 'london':

      

+9


source


You can use string1.lower () for the answer, and then you can make a variable for London instead of string1.lower ().

Example:



string1 = 'Hello' string2 = 'hello'

if string1.lower() == string2.lower():
    print "The strings are the same (case insensitive)"
else:
    print "The strings are not the same (case insensitive)"

      

0


source


You can use .capitalize ()

answer = raw_input().capitalize()

      

-1


source







All Articles