python - Minor issue in using dictionary and isspace function -


here code simple caesar's cipher-style program.

it works fine otherwise, not recognize potential spaces between words written user.

while program translates letters correctly, prints characters clustered in single word, omitting spaces.

i tried solve myself, instead program writes error code: "attributeerror: 'dict' object has no attribute 'isspace'".

is there way?

key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t',        'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a',        'o':'b', 'p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h',        'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'a':'n', 'b':'o',        'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v',        'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c',        'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j',        'x':'k', 'y':'l', 'z':'m'}   def change(message, new_message):      ch in message:         if ch in key:             new_message += key[ch]         if ch in key.isspace():             new_message += " "     return new_message  def main():      print      message = input("type message here.\n")     new_message = ""     print(change(message, new_message))  main() 

change line if ch in key.isspace(): if ch.isspace():


Comments