【发布时间】:2018-05-03 07:31:42
【问题描述】:
我一直在开发一个旨在加密用户输入的消息的程序。有两个加密选项,第二个是为了让消息中的每个字符都像字母表颠倒时的样子。当我输入消息时,我收到错误“AttributeError: 'function' object has no attribute 'find'”。
elif option1 == 2:
def alphabet():
alphabet = 'abcdefghijklmnopqrstuvwxyz'
'abcdefghijklmnopqrstuvwxyz'.reverse() == 'zyxwvutsrqponmlkjihgfedcba'
'abcdefghijklmnopqrstuvwxyz' [::-1] == 'zyxwvutsrqponmlkjihgfedcba'
message = raw_input('What message would you like to encrypt?')
message = raw_input('What message would you like to encrypt?')
for character in message:
position = alphabet.find(character)
newPosition = (position) % 26
newCharacter = alphabet[newPosition]
print(newCharacter)enter code here
我的结构类似于第一个选项的代码,它运行时没有任何问题,我知道这个错误可能源于我不完全确定如何正确结构的 def 语句。
if option1 == 1:
add = 13
message = raw_input('What message would you like to encrypt?')
for character in message:
if character in alphabet:
position = alphabet.find(character)
newPosition = (position + add) % 26
newCharacter = alphabet[newPosition]
print(newCharacter)
我了解此类问题在本网站上经常被问到,但这些问题的答案对我没有帮助,因为我的编程经验很少。
【问题讨论】:
-
def alphabet():alphabet是一个函数,你写的alphabet.find(...)是什么意思?
标签: python function object attributeerror