How can I make the same_name function ignore the case of the strings?


#1

Question

In this exercise, the same_name() function will compare the two names to see if they are equal. How can this be done so that it will ignore any differences in capitalization?

Answer

This can be done by converting the strings to all lower-case using lower() OR all upper-case using upper() before performing the equality test. The upper() and lower() methods are called on the string variables. For example, to compare the strings as lower-case, the check can be written as:

if your_name.lower() == my_name.lower():

The same would apply for using upper().