+10

Hi - I'm new at coding. Could someone please help me write a code which gives a mirror output of an in input string?

I have defined the universe as {'b': 'd', 'd' : 'b', 'o': 'o', 'p' : 'q' ....} I have given an input but am unsure how to take it forward to get to the output. Example: if the input is 'vow'; the desired output should be 'wov'. Any help would be appreciated. Thanks

4/5/2020 7:52:07 AM

Snigdha Datta

48 Answers

New Answer

+5

We can only mirror d,b,q,p Here is the code i reckon that you're looking for: dict={'q':'p','p':'q','d':'b','b':'d'} x=input()[::-1] a='' for i in x: if i in dict: i=dict[i] a+=i print(a)

+3

Hi - thanks for the responses but I do not need only reversing of the letters. I need them to be mirrored...i.e. they should also be visually reversed. Example: for a random input of "poiw", the output should be "wioq" Thanks again

+3

Snigdha Datta As I'm not sure what you exactly want reverse or mirror after reading the suggestions, but question says , "Mirror" : -- old code edited & resaved -- https://code.sololearn.com/cC4CETbktz2J/?ref=app

+2

You mean this? x='hello world' print(x[::-1]) #this would print #dlrow olleh

+2

You may find answer in https://www.tutorialspoint.com/python-program-to-find-mirror-characters-in-a-string

+2

You may find answer in https://www.tutorialspoint.com/python-program-to-find-mirror-characters-in-a-string

+2

istr=input() print(istr[::-1]) I think this will give an mirror output of given string

+2

Thanks for all your inputs - this would help me learn some other concepts on python, as well.

+2

# first take the user input a = input() # Reverse the list a = a[::-1] # print the list print(a) #Or you could also have used " a = a.reverse()" # Or use " a=' '.join(reversed(a)) "

+2

If you want words reversed only you can split the string into a list and operate on each index (or word in this case) and reverse it with the reverse method or [::-1] and then use the join method to put them back together

+2

n = input() print(n[::-1)

+1

Try using this reverse slicing. text = "Hello" print (text[::-1]) >>> olleH It will slice the string in reverse order.

+1

This one is very simple. You can do it with List slicing Ex- word=input() print(word[::-1]) It'll do your work Explanation : The third parameter determines the order of string, if you put negative value in it it'll reverse the order of the string. Also, putting negative values in the first two will count from the end of the list.

+1

Im still lost. How can P be reversed? wouold you need to determin it via a dictionary?

+1

You should read about List slice in detail. You do not dictionary for this. It's a simple procedure

+1

U know python or just starting it??

+1

Ramya Thiurmalisamy First try to understand this code: x=[0,1,2,3,4,5] #using ":" will print everything print( x[ : ] ) >>>[0,1,2,3,4,5] #if we want to step 2 numbers we can use third argument as print( x[ 0 : 5 : 2 ] ) >>>[0,2,4] #if we want to start from back we write in the same way but with "-" sign (note: from back the index of 1st digit is -1 not 0 print( x[ -1 : -5 : -2] ) >>>[5,3,1] #now if we want to to print everything without giving indices of 1st two arguments we can use ":" as described earlier(here we used two colons to skip middle argument and include the 3rd argument) print( x[ : : -2] ) >>>[4,2,0] #and if we don't want to skip we can write as print( x[ : : -1] ) >>>[5,4,3,2,1,0] I hope now you have understood the reversing of list.

+1

u_input = input() Print(u_input[0:0:-1])

+1

# For mirror output of string Name = input("enter a word") Name.lower() Print(Name(::-1))

+1

a=input print (a[::-1]) This would be the most simplest code to use in this case