Python Forum
letter translator (or someting)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
letter translator (or someting)
#1
i'm trying to make a translator (i'm not sure that's called translator) that changes every letter to it's equivalent in it's alternative version(for example a=o). i wrote something but it's not working.
Alp1 = "abcdefghıjklmnoprstuvyzxqwABCDEFGHIJKLMNOPRSTUVYZXQW"
Alp2 = "ozskadcmufvhpnebtgyijrlxwqOZSKADCMUFVHPNEBTGYİJRLXWQ"


def variable(word,Num1=0, Num2=0,):
    while Num2 != len(word) + 1:
        Num1 = 0
        Num2 += 1
        while word[Num2] != Alp1[Num1]:
            Num1 += 1
        word[Num2] = Alp2[Num1]
        return word


print(variable(input("enter the word:")))
what do i do?
Reply
#2
Read up on python string operators. You may FIND something here

https://docs.python.org/2/library/string.html
Reply
#3
Use this dictionary to translate
for i in range(0,len(Alp1)):
   dct[Alp1[i]]=Alp2[i]
Reply
#4
(Apr-28-2020, 01:56 AM)deanhystad Wrote: Read up on python string operators. You may FIND something here

https://docs.python.org/2/library/string.html

if, as I guess, @deanhystad is pointing in direction of string.maketrans() - it was depreciated in 3.1 and removed in 3.2.
It's now static method of built-in str type. Look into it in combination with translate() method
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Arrrgh! It bugs me that my link to python docs always takes me to 2.7 and this is not the first time I forgot to change to the 3.8 version. If we asked really nice do you think the internet would erase all python information prior to version 3, or in this case maybe version 3.6?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,600 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  i want to write symbole as varibales in python to make translator rachidel07 9 3,495 Feb-03-2021, 09:57 PM
Last Post: nilamo
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 2,100 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Trouble with Regex Translator skrivver99 3 2,762 Dec-15-2018, 03:55 PM
Last Post: Gribouillis
  Output discrepancy when building Translator skrivver99 17 6,640 Nov-26-2018, 01:22 AM
Last Post: ichabod801
  Help with pig latin translator DragonG 1 2,265 Nov-01-2018, 03:57 AM
Last Post: ichabod801
  PigLatin Sentence Translator Help 2skywalkers 7 5,799 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers
  Pig Latin Translator RickyWilson 1 3,179 Dec-02-2017, 08:20 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020