help me in this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

help me in this

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::: re = list([val for val in code if val.isalpha()]) result = "".join(re) resul = result.split( ) resu = " ".join(resul) print(resu[::-1]) i am unable to print (you are great) the spaces in between them

18th May 2020, 8:16 AM
Akshat Jain
10 Answers
+ 7
don't filter spaces val.isalpha() or val == " "
18th May 2020, 8:36 AM
Oma Falk
Oma Falk - avatar
+ 6
Rik Wittkopp I detest violence 😉 Maybe I find another way to punish you. nope.... just kidding 😂 nothing wrong with your answer
18th May 2020, 9:04 AM
Oma Falk
Oma Falk - avatar
+ 4
Oma Falk beat me to it. The problem is within your re= etc This section of your code will only return the letters from your code, omitting numbers, special characters & SPACES. So, you must define this section of code to include the SPACES, ergo: or val is ' ' code = '4s5#i%+h7t 3t^s74e$#t$*&' #print(''.join(i for i in code[::-1] if i.isalpha() or i is chr(32))) re = list([val for val in code if val.isalpha() or val is ' ']) result = "".join(re) resul = result.split() resu = " ".join(resul) print(resu[::-1])
18th May 2020, 8:57 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Oma Falk You scared me. 🤣
18th May 2020, 9:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
20th Jan 2023, 5:16 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
Solving the problem by using JAVA: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner(System.in); char ch; String nString = " "; String txt = scan.nextLine(); for(int i = 0; i<txt.length();i++){ ch = txt.charAt(i); nString = ch + nString; } for(String j: nString.split(" ")){ String tt = j.replaceAll("[^a-zA-Z]", ""); System.out.print(tt+" "); } } }
19th Jan 2022, 3:07 AM
Moussa Diallo
Moussa Diallo - avatar
0
enc = input() enc = enc.replace(" ","wegow") efilter = filter(str.isalpha,enc) enc = "".join(efilter) enc = enc.replace("wegow"," ") enc = enc[::-1] print(enc)
4th May 2022, 10:21 PM
Mohamed Wagdy
Mohamed Wagdy - avatar
0
a=input() b= [var for var in a if var.isalpha() or var ==" "] #print(b) c= "".join(b) #print(c) print (c[::-1])
30th Aug 2022, 3:11 AM
amir esmaeeli
amir esmaeeli - avatar
0
Hi can i know what is this language is it paython or c++
20th Jan 2023, 4:53 PM
Nada Jayune
0
My solution with python mess = input() mess = mess[::-1] message ="" alphabet=","" abcdefghijklmnopqrstuvwxyz" for i in mess : for j in alphabet : if i == j: message += i print(message)
5th May 2023, 9:22 AM
Oussama Kadimallah
Oussama Kadimallah - avatar