I am solving secret message challenge please tell me how to add space in my output
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)
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)
You could make another if-statement checking if the current character is space and if it is, then add it to your output string
add space to the characters like bellow x="abcdefghijklmnopqrstuvwxyz " y="zyxwvutsrqponmlkjihgfedcba "
Thanks to you all for the help
Space is added in the output