+ 3

I am solving secret message challenge please tell me how to add space in my output

https://code.sololearn.com/cDXvDzws1Tom/?ref=app

14th Sep 2021, 2:49 PM
Vaibhav Tiwari
6 ответов
+ 2
Vaibhav Tiwari first change this line: new_str = y[ind] + new_str To new_str = new_str + y[ind] then add else part else: new_str = new_str + char --------+++--------- for char in txt: if char in y: ind = x.index(char) new_str = new_str + y[ind] else: new_str = new_str + char print(new_str)
14th Sep 2021, 3:13 PM
A͢J
A͢J - avatar
+ 5
Vaibhav Tiwari , ▪︎to handle spaces: you only need to modify variable x and y. just insert a space as first character in both of them ▪︎ issue with encoding: when adding the 'new' characters to the 'new' string, you should use this: new_str = new_str + y[ind] (compare it with your code)
14th Sep 2021, 4:13 PM
Lothar
Lothar - avatar
+ 1
You could make another if-statement checking if the current character is space and if it is, then add it to your output string
14th Sep 2021, 2:55 PM
Lisa
Lisa - avatar
+ 1
add space to the characters like bellow x="abcdefghijklmnopqrstuvwxyz " y="zyxwvutsrqponmlkjihgfedcba "
14th Sep 2021, 4:49 PM
Sacalivin Obiri
Sacalivin Obiri - avatar
+ 1
Thanks to you all for the help
15th Sep 2021, 2:19 AM
Vaibhav Tiwari
0
Space is added in the output
15th Sep 2021, 2:19 AM
Vaibhav Tiwari