Question

Write a function is_mirror(s) that takes as input a string s and returns True if s...

  • Write a function is_mirror(s) that takes as input a string s and returns True if s is a mirrored string (i.e., a string that could have been produced by your mirror function) and False otherwise. Examples:

    >>> is_mirror('baconnocab')
    result: True
    
    >>> is_mirror('baconnoca')
    result: False
    

    Warning

    Your function should return a boolean value – either True or False, without any quotes around them. If you see quotes around the result when you make the calls above from the console, you must fix your function to return a boolean and not a string.

    Hints:

    • You may find it helpful to compute the value len(s) // 2 as part of this function.
    • You may also find it helpful to call your previous mirror function, although doing so is not required.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def is_mirror(s):
    i = 0
    j = len(s)-1
    while(i<j):
        if(s[i]!=s[j]):
            return False
        i += 1
        j -= 1
    return True
Add a comment
Know the answer?
Add Answer to:
Write a function is_mirror(s) that takes as input a string s and returns True if s...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function “ssnChecker” that takes a string “s” and validates if the string is in...

    Write a function “ssnChecker” that takes a string “s” and validates if the string is in a valid social security number format (999-99-9999). The function must return a Boolean value (True or False).

  • Write a recursive function, take a String as input, return true, if the String is a...

    Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...

  • Write a function check palindrome, which takes a string x as argument and which returns True...

    Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....

  • sorted vowels Write a function that returns true if the vowels in the input string A...

    sorted vowels Write a function that returns true if the vowels in the input string A appear in non-decreasing order and false otherwise. You can assume this function is not case sensitive. If the string does not contain any vowels, it must return true. bool sorted_vowels (const char A)

  • Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if...

    Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if s1 is the reverse of s2, false otherwise. Then, draw the sequence of recursive calls for the following cases. Submit your diagrams in a PDF file called isReverseTrace.pdf. isReverse("happy", "yppah") will return true isReverse("cool", "loac") will return false isReverse("", "") will return true

  • C++ Programming: Write a function that takes in a C++-style string s (from #include ), as...

    C++ Programming: Write a function that takes in a C++-style string s (from #include ), as well as an integer n, and then returns true if any substring of length n in s repeats itself, and false otherwise. For example, if s is "toe-to-toe" and n is 3, then the function would return true since "toe" occurs twice within s. However, if n were 4, the function would return false. As a second example, if s is "singing" and n...

  • Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true...

    Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool

  • Python Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence...

    Python Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence seq, and that uses recursion (i.e., that calls itself recursively) to find and return the index of the last occurrence of elem in seq. The sequence seq can be either a list or a string. If seq is a string, elem will be a single-character string; if seq is a list, elem can be any value. Don’t forget that the index of the first...

  • 1. Write a function in Tree class which returns true if and only if the tree...

    1. Write a function in Tree class which returns true if and only if the tree satisfies the binary search tree property. The function’s header line is public boolean isValidBST() And in the attached code, you just need to finish the function after the comment: “//Instructor hint: please write your code here:” Make sure you execute your code, and the result in the main function after calling your function should be same as the prompt message I write. Clearly you...

  • C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if...

    C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if the string contains the digits in descending order. The function can ignore (e.g. skip checking) all the characters that are not digits in the string. Empty string will return false. For example, string of “95421” or “862” or “8622” or “88” or “9” will return true and string of “95423” or “889” or “9445” or “449” or “” will return false.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT