promotion image of download ymail app
Promoted

Python help?

Define a function named last_position_disagree(...) which receives as parameter two strings str1 and str2 of the same length, consisting only of letters, and returns the last position where the two strings have different letters. Upper case and lower case versions of the same letter are treated as being identical. If there is no such position, the value -1 should be returned. Hint: Consider visiting the strings backwards.

As an example, the following code fragment:

str1 = "hallo"

str2 = "hxlxo"

print(last_position_disagree(str1,str2))

should produce the output:

3

1 Answer

Relevance
  • 2 months ago

    Hi, StrugglingStudent.

    "Hint: Consider visiting the strings backwards." Do you know how to do this?

    Answer:

    def last_position_disagree (str1, str2):

        for i in range (len (str1)-1, -1, -1): # index i goes from last letter index to first

    Your next line of code should be an if statement. I will let you figure out the rest.

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.