python - How to deal with IndentationError? -
i following error:
file "imp.py", line 55 key = key() ^ indentationerror: expected indented block
with following code:
# caesar cipher max_key_size = 26 def getmode(): while true: print('do wish encrypt or decrypt or brute force message?') mode = raw_input().lower() if mode in 'encrypt e decrypt d brute b'.split(): return mode else: print('enter either "encrypt" or "e" or "decrypt" or "d" or "brute" or "b".') def getmessage(): print('enter message:') return raw_input() def getkey(): key = 0 while true: print('enter key number (1-%s)' % (max_key_size)) key = int(raw_input()) if (key >= 1 , key <= max_key_size): return key def gettranslatedmessage(mode, message, key): if mode[0] == 'd': key = -key translated = '' symbol in message: if symbol.isalpha(): num = ord(symbol) num += key if symbol.isupper(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 elif symbol.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 translated += chr(num) else: translated += symbol return translated mode = getmode() message = getmessage() if mode[0] != 'b': key = getkey() print('your translated text is:') if mode[0] != 'b': print(gettranslatedmessage(mode, message, key)) else: key in range(1, max_key_size + 1): print(key, gettranslatedmessage('decrypt', message, key))
how can fix this?
- do not use
+=
build strings. use''.join(mylist)
- do asks: give indented block.
Comments
Post a Comment