+ 1

Help | Помогите

I want to write a generator of names. For example, if a person inscribes his name, it will be displayed as if replacing the letters in the name. Do not tell me how you can do this? _____________________________________________ Я хочу, написать генератор имён. Например если человек будет вписывать своё имя, то будет выводиться как-бы замена букв в имени. Не подскажете как можно такое сделать ? https://code.sololearn.com/c43dY2U4Y9jG/?ref=app

5th Apr 2018, 1:04 PM
Eegun
Eegun - avatar
5 ответов
+ 2
I assume you wanted to write do tell me and not tell you :D create a dictionary of all letters as keys and into values input what you want. Then iterate over the users input() and store the output into a list or a string with .append() or += and when done just print the new variable.
5th Apr 2018, 3:41 PM
Markus Kaleton
Markus Kaleton - avatar
+ 2
To do this, I would say that there are a few ways for it to work. The first and probably the most straightforward would be using a series of if/elif/else statements checking the value of each character in the string given by the user. You could also set the string in a for loop to check the value of every character in the string. The second way I could think of to do this is to use the re library. With re, you can set a certain string to look for in another string as a substring, with this case the substring being the letter and the larger string being the user input. You could use the re.sub function to replace the letter with whatever sequence of characters you want. Hope this helped!
5th Apr 2018, 1:32 PM
Faisal
Faisal - avatar
+ 1
Eegun Yes. but you could have keys as lowercase and after user input just .lowercase() the input variable
7th Apr 2018, 11:06 AM
Markus Kaleton
Markus Kaleton - avatar
0
idrem if python has a string replacement function but in c# for example you would use Regex.Replace
5th Apr 2018, 1:14 PM
hinanawi
hinanawi - avatar
7th Apr 2018, 10:53 AM
Eegun
Eegun - avatar