+ 3
I am solving secret message challenge please tell me how to add space in my output
6 Respostas
+ 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)
+ 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)
+ 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
+ 1
add space to the characters like bellow
x="abcdefghijklmnopqrstuvwxyz "
y="zyxwvutsrqponmlkjihgfedcba "
+ 1
Thanks to you all for the help
0
Space is added in the output