Question: PYTHON 2. The mirror of the string vow is the string wov and the mirror image of wood is boow. The mirror of the string
PYTHON
2. The mirror of the string vow is the string wov and the mirror image of wood is boow. The mirror of the string bed cannot be represented by a string because the letter e does not have a mirror in the alphabet. Write a function mirror() that takes a string and, if it has a mirror, returns its mirror image. If it does not have a mirror, return the string INVALID. Hint: use a dictionary with the mirrors in it. You can see how to mirror letters by looking at the last example below: >>> mirror('vow') 'wov' >>> mirror('wood') 'boow' >>> mirror('bed') 'INVALID' >>> mirror('pout') 'tuoq' >>> mirror( mirror('pout') ) 'pout' >>> [(c,mirror(c)) for c in 'abcdefghijklmnopqrstuvwxyz'] [('a', 'INVALID'), ('b', 'd'), ('c', 'INVALID'), ('d', 'b'), ('e', 'INVALID'), ('f', 'INVALID'), ('g', 'INVALID'), ('h', 'INVALID'), ('i', 'i'), ('j', 'INVALID'), ('k', 'INVALID'), ('l', 'l'), ('m', 'm'), ('n', 'n'), ('o', 'o'), ('p', 'q'), ('q', 'p'), ('r', 'INVALID'), ('s', 'INVALID'), ('t', 't'), ('u', 'u'), ('v', 'v'), ('w', 'w'), ('x', 'x'), ('y', 'INVALID'), ('z', 'INVALID')]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
