0

Write a Python program that creates upside down sentences, like
upside down --> umop apisdn

The sentence above is flipped 180 degrees around the end.
Some freedom allowed, like an 'a' upside down and reversed is the closest thing to an 'e'. Conversely a 'w' would be a 'm' upside down.

Note:
A silly little thing originally in "Beginners Projects". I moved it here because Tony had such a nice solution.

Edited by vegaseat: moved

Votes + Comments
Unclear, if not wrong, rule of request
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by pyTony
0

I do not understand the rule:

for c in 'umop apisdn':
	print c,'upside down'.find(c)
	
u 0
m -1
o 8
p 1
  6
a -1
p 1
i 3
s 2
d 4
n 10

So 'm' and 'a' is not in other string at all.

0

Write a Python program that creates upside down sentences, like
upside down --> umop apisdn

The sentence above is flipped 180 degrees around the end.
Some freedom allowed, like an 'a' upside down and reversed is the closest thing to an 'e'. Conversely an 'w' would be an 'm' upside down.

Well corrected description, here is little advanced beginners answer with conditional value ('*' if letter is not found in upside down letter dictionary)

##upside down --> umop apisdn
def upside(instring):
    upside_dict = {'u':'n','n':'u',
                   'p':'d','d':'p',
                   's':'s',' ':' ',
                   'o':'o','i':'i',
                   'h':'y', 'y':'h',
                   'a':'e', 'e':'a',
                   'w':'m','m':'w',
                   '6':'9','9':'6', '1':'1','0':'0',
                   }
    return ''.join([(upside_dict[char] if char in upside_dict else '*') for char in instring[::-1]])


for instring in ('upside down','daniweb'):

    print instring,'->',upside(instring)

Edited by pyTony: n/a

0

Maybe it is not proper to post code here as answer? Sorry about above post, but I felt compelled to post it after my request for clarification. You can remove it and the request.

Note:
Thanks for spending some time with this! Moved it to the regular forum.

Edited by vegaseat: moved per request

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.