Sajan Nair
Sajan Nair

Reputation: 13

Python Mirroring code

Hi new to python learning ....from

http://interactivepython.org/courselib/static/thinkcspy/Strings/strings.html#exercises

Q 7: Write a function that mirrors its argument ?

Answer I Wrote

def mirror(mystr):

oppstring = " "
for i in mystr:
    oppstring = i + oppstring
finstring = mystr + oppstring
return finstring

Ans in text book

def reverse(mystr):

reversed = ''
for char in mystr:
    reversed = char + reversed
return reversed

def mirror(mystr):

return mystr + reverse(mystr)

When i use the function values for both functions seem to be the same ...yet 'testequal" shows my answer as "Test Failed: expected gooddoog but got gooddoog "......Am i doing some thing wrong ....or is it just some thing wrong with the webpage.....

Regards >>

Upvotes: 0

Views: 529

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799440

Your problem is in this line. Look closely:

oppstring = " "

Upvotes: 1

Related Questions