0

I began this code by using a while loop to establish the menu (line 19-40) and it worked perfectly before adding the functions and import at the top. Now it keeps throwing back an indentation error at line 19 and none of my attempts other than removing all the functions seem to fix this problem. Any chance I overlooked something?

import string

def encrypt(input_val):
    en_key = input("Enter the number to shift by:")
    var = to_encrypt.upper()

    for char in var:
        shift = ord(char) + en_key
        encrypted += chr(shift)
        return encrypted.upper()

def decrypt(input_val):
    de_key = input("Enter the number to shift by:")
    var = to_decrypt.upper()

    for char in var:
        shift = ord(char) - de_key
        decrypted += chr(shift)
        return decrypted.upper()

def crack(input_val):


program_on = True
while program_on == True:
    print("Please select from the following options:\n \t1. Encrypt A Message\n \t2. Decrypt A Message\n \t3. Attempt To Crack A Message\n \t4. Quit")
    user_choice = input("Enter Your Choice: ")
    if user_choice == "1":     
        to_encrypt = input("Enter message to encrypt:")
        encrypt(to_encrypt)
        program_on = True
    elif user_choice == "2":
        to_decrypt = input("Enter encrypted message:")
        decrypt(to_decrypt)
        program_on = True
    elif user_choice == "3":
        to_crack = input("Enter encrypted message:")
        crack(to_crack)
        program_on = True
    elif user_choice == "4":
        print("Goodbye")
        program_on = False
    else:
        print("Give a valid response")
        program_on = True
3
  • 2
    As posted here, the error is obvious; there are no indented lines after def crack(input_val):. Commented Mar 16, 2014 at 1:49
  • Indentation is significant in Python and IndentationError means you did not follow it. I suggest reading the docs for your version of Python. Commented Mar 16, 2014 at 1:49
  • Looks like you lost the body of the crack() function; nothing else in your post is an obvious fit. Commented Mar 16, 2014 at 1:53

1 Answer 1

1

Seems to work now.

 def crack(input_val):
      pass

You can't define an empty function.

Sign up to request clarification or add additional context in comments.

5 Comments

Since the while loop below it is calling crack() it looks more like the body of crack was lost somewhere.
I was thinking he just hadn't written it yet and couldn't understand why having the empty function was preventing him from compiling and he just needed 'pass' as a placeholder.
Yup, agreed, but I was referring to your last sentence, which suggests to indent all of the while loop.
I was thinking that was a possibility until you pointed out the meaningless recursion, but you're right, edited it.
I knew it was something simple that I was just overlooking. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.