0

What is the error in it??

You are a secret agent, and you receive an encrypted message that needs to be decoded. The code that is being used flips the message backwards and inserts non-alphabetic characters in the message to make it hard to decipher. Task: Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message. Input Format: A string of characters that represent the encoded message. Output Format: A string of character that represent the intended secret message. Sample Input: d89%l++5r19o7W *o=l645le9H Sample Output: Hello World My code: def func(str): r = [] for j in str: if j in "zxcvbnmlkhjgfdsaqwertyuiopZXCVBNMLKJHGFDSAPOIUYTREWQ": r.append(j) r=r[::-1] for k in r: print(k) func(input())

1st Jan 2022, 8:32 AM
Ravi King
3 Answers
+ 5
Ravi King , (1) instead of writing all the letters or importing asci_letters, it is also possible to use 2 string methods as conditions: ... if j.isalpha() or j.isspace(): ... (2) currently the code outputs each letter in a new line. this is not what the task description mentioned. you can modify your code to do the output in one line: (trying to keep the code as close as it is done by you) ... print(k,end="") ...
1st Jan 2022, 9:44 AM
Lothar
Lothar - avatar
+ 4
I see that it doesn't take spaces. Also go in some kind of order when you type all those letters, it's very easy to forget one of the 52 variants.
1st Jan 2022, 8:35 AM
Slick
Slick - avatar
+ 1
Slick mentioned it correct. You can also use built in ascii_letters from string module to get all letters rather than typing like this. from string import ascii_letters as al #to get ascii_letters and store it in al variable
1st Jan 2022, 9:19 AM
Sanjyot21
Sanjyot21 - avatar