Help me to fix the error?? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Help me to fix the error??

a = {'a':'z','b':'y','c':'x','d':'w','e':'v','f':'u','g':'t','h':'s','i':'r','j':'q','k':'p','l':'o','m':'n','n':'m','o':'l','p':'k','q':'j','r':'i','s':'h','t':'g','u':'f','v':'e','w':'d','x':'c','y':'b','z':'a'} b = input() for key , value in a.items(): b = b.replace(key,value) print(b) Here's the question: You are trying to send a secret message, and you've decided to encode it by replacing every letter in your message with its corresponding letter in a backwards version of the alphabet. What do your messages look like? Task: Create a program that replaces each letter in a message with its corresponding letter in a backwards version of the English alphabet. Input Format: A string of your message in its normal form. Output Format: A string of your message once you have encoded it (all lower case). Sample Input: Hello World Sample Output: svool dliow

19th Jul 2021, 2:29 PM
Shahir
Shahir - avatar
16 ответов
+ 8
Shaik.Shahir , before we can help you, you should show us your attempt first. if you have not done a try by yourself upto now, please do so. Put your code in playground and link it here. thanks!
19th Jul 2021, 2:40 PM
Lothar
Lothar - avatar
+ 4
a = {'a':'z','b':'y','c':'x','d':'w','e':'v','f':'u','g':'t','h':'s','i':'r','j':'q','k':'p','l':'o','m':'n','n':'m','o':'l','p':'k','q':'j','r':'i','s':'h','t':'g','u':'f','v':'e','w':'d','x':'c','y':'b','z':'a'} b = input() for key , value in a.items(): b = b.replace(key,value) print(b) What is missing in this code??
20th Jul 2021, 6:52 AM
Shahir
Shahir - avatar
+ 3
This task has one subject: To find the corresponding character in an reversed alphabet and replace it. For me, you can create two main variables, one that contains the regular alphabet, and one another that contains the reversed alphabet. Then, iterating over each character of the current word, find its index and return the same index but at the reversed alphabet. And that's it ! Just be a little smart and share your try here from the code playground 😁👋
19th Jul 2021, 2:49 PM
Ervis Meta
Ervis Meta - avatar
+ 3
No it's not working
20th Jul 2021, 9:36 AM
Shahir
Shahir - avatar
20th Jul 2021, 11:18 AM
Ervis Meta
Ervis Meta - avatar
+ 2
Shaik.Shahir I'm really sorry for giving you the incorrect code. I've updated mine, so you may check that out. Here's a working version of your code: a = {'a':'z','b':'y','c':'x','d':'w','e':'v','f':'u','g':'t','h':'s','i':'r','j':'q','k':'p','l':'o','m':'n','n':'m','o':'l','p':'k','q':'j','r':'i','s':'h','t':'g','u':'f','v':'e','w':'d','x':'c','y':'b','z':'a'} for x in input().lower(): print(a.get(x, x), end="") # Hope this helps
20th Jul 2021, 11:07 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Would please explain me the using of "get" function?
20th Jul 2021, 11:14 AM
Shahir
Shahir - avatar
+ 2
low = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] upp = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] prompt = input() for c in prompt: if c.islower(): count = low.index(c) if count == 0: rev = count -1 elif count > 0: rev = (count * (-1)-1) print(low[rev]) if c.isupper(): count = upp.index(c) if count == 0: rev = count -1 elif count > 0: rev = (count * (-1)-1) print(upp[rev])
20th Jul 2021, 12:34 PM
Ale
Ale - avatar
+ 1
I feel like the instructions are fairly clear. It wants you to take an input string, say "dog", and encode it by taking the alphabet, and reversing its order (ie, instead of 'abcd...' it's 'zyxw...'). So for "dog", we'd have "wlt". so here's the input/output format: input: dog output: wlt From here on it's up to you to figure out.
19th Jul 2021, 2:53 PM
BootInk
BootInk - avatar
+ 1
Shaik.Shahir I guess that the input needs to be in the lower form. Try changing the first line to b.input().lower().
20th Jul 2021, 8:38 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Shaik.Shahir The get() method of the dict class returns the corresponding value if the first argument (the key) is found. Else, it returns the second argument.
20th Jul 2021, 12:44 PM
Calvin Thomas
Calvin Thomas - avatar
0
I don't understand the output format in the question So please explain it!
19th Jul 2021, 2:43 PM
Shahir
Shahir - avatar
0
Abcdefghijklmnopqrstuvwxyz becomes Zyxwvutsrqponmlkjihgfedcba First position in first string becomes first position in second string. And so on.
19th Jul 2021, 2:56 PM
Paul
Paul - avatar
0
Shaik.Shahir You may try using the ord() function to make the job easier.
20th Jul 2021, 5:56 AM
Calvin Thomas
Calvin Thomas - avatar
0
Shaik.Shahir Here's a possible solution: https://code.sololearn.com/cP4X13LiMhqT/?ref=app # Hope this helps
20th Jul 2021, 8:37 AM
Calvin Thomas
Calvin Thomas - avatar
0
list = { 'a': 'z','b': 'y', 'c': 'x','d': 'w', 'e': 'v','f': 'u', 'g': 't','h': 's', 'i': 'r','j': 'q', 'k': 'p','l': 'o', 'm': 'n','n': 'm', 'o': 'l','p': 'k', 'q': 'j','r': 'i', 's': 'h','t': 'g', 'u': 'f','v': 'e', 'w': 'd','x': 'c', 'y': 'b','z': 'a' } string = str(input()) a = '' for char in string.lower(): if char == " ": a += char else: a += list[char] string = a print(string)
15th Sep 2021, 8:10 AM
Agven Muharis Rifqi
Agven Muharis Rifqi - avatar