Python程序返回错误我似乎无法修复

时间:2014-03-16 01:47:03

标签: python

我通过使用while循环来建立菜单(第19-40行)开始使用此代码,并且在添加函数并在顶部导入之前它完美地工作。现在它不断在第19行抛出缩进错误,除了删除所有函数之外我没有尝试解决这个问题。我有没有机会忽略某些事情?

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

1 个答案:

答案 0 :(得分:1)

似乎现在正在工作。

 def crack(input_val):
      pass

您无法定义空函数。