+ 3

Spy life

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 https://code.sololearn.com/cOHaV3D1TZOr/?ref=app

19th Apr 2022, 9:45 AM
aazizul zainal
aazizul zainal - avatar
5 odpowiedzi
+ 3
code = input()[::-1] lst=["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"," "] for i in range(len(code)): if code[i] == lst: #comparing with total list instead of single character. instead use code[I] in lst: sentence == "" #no effect sentence , are you trying to assigne? then use = operator, == is a comparision operator, but declare this sentence outside and before loop, otherwise each time it overrites value sentence =+ code[i] #use += , not =+ print(sentence) # instead of list , you can use isalpha() function edit: your missing space count.. Space must be in output as it is as in input reversed way.. isspace() helps to check.
19th Apr 2022, 10:28 AM
Jayakrishna 🇮🇳
+ 2
aazizul zainal , instead of using the alphabet as a reference for checking each character, we could also use the string methods: .isalpha() .isspace() to get the task done: ... for char in ...: if char.isalpha() or ...: ...
19th Apr 2022, 4:39 PM
Lothar
Lothar - avatar
+ 2
code = input()[::-1] lst=["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"," "] sentence = "" for i in range(len(code)) : if code[i] in lst: sentence += code[i] print(sentence)
21st Apr 2022, 4:18 AM
mohammed shibli
mohammed shibli - avatar
+ 1
If anyone got any idea how can i approach this problemm,feel free too critics or give me any suggestion for my next python project, i really stuck on this one :/
19th Apr 2022, 9:46 AM
aazizul zainal
aazizul zainal - avatar
+ 1
aazizul zainal just remove all the number and special characters(except spces) from the sample input after that you will have a string of only letters reverse that strings you will get your output Note carefully there is a space between W and * in your current code you are not checking for the presence of code[i] in lst[i] line 7 needs = operator not == line 8 should be += not =+
19th Apr 2022, 10:35 AM
NonStop CODING
NonStop CODING - avatar