我创建了一个密码,收到了一条错误消息:
TypeError: 'str' object is not callable
我目前的代码是:
alphabet = "abcdefghijklmnopqrstuvwxyz"
key = 5
cipher = ' '
choice = input('Do you wish to encrypt or decrypt? E/D')
if not choice == 'D' and not choice == 'E':
raise Exception('Must enter E or D for Encrypt or Decrypt')
user_input = input('Please enter your word')
cipher2 = cipher (user_input, alphabet, choice, key)
print('your encrypted mesaage 2 is: ' + cipher2)
#Method can encrypt or decrypt the entered word
def cipher(plain_text, alphabet, choice, key):
cipher = ''
for c in plain_text:
if c in alphabet:
if choice == 'E':
val1 = alphabet.index(c)
val2 = key
cipher += alphabet[ (val1 + val2) % (len(alphabet))]
elif choice == 'D':
cipher = cipher + alphabet[ (alphabet.index(c)-key) % (len(alphabet))]
return cipher
错误在第九行:
cipher2 = cipher (user_input, alphabet, choice, key)
如果有人能帮忙,我会很感激的
字符串
cipher
(在第3行中定义)与函数cipher
具有相同的名称:当您调用这个check
cipher
类型时,它是string
,所以请更改您的字符串名或函数名。你知道吗相关问题 更多 >
编程相关推荐