362,879 views
17 votes
17 votes
For function isreverse, write the two missing base case conditions. Given two strings, this function returns true if the two strings are identical, but are in reverse order. Otherwise it returns false. For example, if the inputs are tac and cat, then the function should return true.

User Mtrovo
by
2.9k points

2 Answers

19 votes
19 votes

Final answer:

The missing base cases for the isreverse function should return true when both strings are empty and when strings have a length of one, it should check if they are the same character.

Step-by-step explanation:

The student is asking for the missing base case conditions in a function that determines if two strings are reverses of each other. In recursion, base cases are essential to halt the recursion. For the isreverse function, the two missing base cases should address the following conditions:

When both strings are empty, the function should return true because two empty strings are reverses of each other.

When the length of the strings is one, the function should check if they are the same character. If so, return true; otherwise, return false.

By implementing these base cases, the function can correctly determine if longer strings are reverses by recursively checking each character in sequence.

User Jamagas
by
3.1k points
9 votes
9 votes

Answer:

def isrreverse(str1, str2):

return str1 == str2[::-1]

Step-by-step explanation:

User Cris
by
3.5k points