Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create strange calculator

hello everyone I have a question .

I am creating a translator in python . This translator is going to change a normal text to a text with some special things :

  1. At the first of each word we add "S"
  2. At the End of each word we add "Di"
  3. We reverse each word

example :
Hello Everyone –> SHello SEveryone –> SHelloDi SEveryoneDi –> iDolleHS iDenoyrevES

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I did first two parts easily; but third part is a little tricky
my code :

n = input("Enter Text : ")
y = n.split()
z = 0

for i in y:
    x = str("S" + i)
    y[z] = x
    z = z + 1

z = 0

for i in y:
    x = str(i + "Di")
    y[z] = x
    z = z + 1

print(y)

z = 1

for i in y:
    globals()["x%s" % z] = []
    for j in i:
        pass

in pass part i wanna to do something like this : x{i}.append(j)
and then we reverse it .

Is there anyone whi can help me with this code ??

>Solution :

You can reverse it using ::-1, it means from start to beginning in reverse order:
For example:

print("abcd"[::-1]) # will prin dcba

So the code for every word can look like this:

result = "S"+word+"Di"
result = result[::-1]

Now you just have to put that in a loop and do it for every word.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading