Skip to content
Advertisement

is_reverse “second” error in Think Python

There is an is_reverse program in Think Python as follows:

JavaScript

The author asks to figure out an error in it which I am unable to after much brainstorming.

The program works just fine and returns this:

JavaScript

The error pertains to this output. Please help me figure it out.

Advertisement

Answer

The function suppose to check if word1 is reserve of word2 (I think, please post what you expect the function to do next time)

The function does not check final word and beginning word. It does not check word1[-1] (last character) and word2[0] (first character)

JavaScript

The problem is here:

JavaScript

The loop terminate before checking word2[0]. I suggest add =. THus, change the condition to:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement