S
S
Skrayvee2021-08-22 21:30:17
Python
Skrayvee, 2021-08-22 21:30:17

replace doesn't work. I would be glad to help (without "learn python")?

I want to make a bot that encrypts a message, but replace() does not work

sh_txt = data['sh_txt']
  shifr = ''
  shifr += sh_txt
  
  shifr.replace('А', "Г")
  shifr.replace('а', 'г')
  shifr.replace('Б', "Д")
  shifr.replace("б", "д")
  shifr.replace("В", "Е")
  .............................
        #и так далее
  
  
  await msg.answer(f'{shifr}', reply_markup=gens)

Letter substitution does not work.
If I enter "A", the output is the same when it should be "G"

UPD:
I searched in Google. No need to say "google it" or "learn python"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sswwssww, 2021-08-22
@Skrayvee

shifr = 'АаБбВ'
mapping = {
    'А': 'Г',
    'а': 'г',
    'Б': 'Д',
    'б': 'д',
    'В': 'Е'
}
table = str.maketrans(mapping)
shifr = shifr.translate(table)

S
Sergey Gornostaev, 2021-08-22
@sergey-gornostaev

It is necessary not to search in Google, but to read the textbook.
PS We don't need to be told what to say.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question