无法使用remove()
我正在应对制作凯撒密码编码器的挑战。当我遇到这个无法修复的错误时,我正在修复一些错误。请帮助解决这个问题。哦。这是代码。
d = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
#TODO-1: Create a function called 'encrypt' that takes the 'text' and 'shift' as inputs.
def encrypt(text, shift):
shit = int(shift)
alphabet = d
for counter in range(0, shit):
x = len(d) - 1
y = d[x]
alphabet = alphabet.reverse()
alphabet = alphabet.remove(0)
alphabet = alphabet.insert(0, y)
print(d)
encrypt("Hello", "9")
我以为我把remove()拼写错了。我决定复制粘贴它。当我给出轮班号时,我本以为它会向我显示混合的字母表。发生的事情是它给了我这个错误:
Traceback (most recent call last): File "main.py", line 17, in <module> encrypt("Hello", "9") File "main.py", line 14, in encrypt alphabet = alphabet.remove(0) AttributeError: 'NoneType' object has no attribute 'remove'
I was Working on a challenge for making a cipher caesar encoder. I was fixing some errors when I came across this error I couldn't fix. Please help with this problem. Oh. and here's the code.
d = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
#TODO-1: Create a function called 'encrypt' that takes the 'text' and 'shift' as inputs.
def encrypt(text, shift):
shit = int(shift)
alphabet = d
for counter in range(0, shit):
x = len(d) - 1
y = d[x]
alphabet = alphabet.reverse()
alphabet = alphabet.remove(0)
alphabet = alphabet.insert(0, y)
print(d)
encrypt("Hello", "9")
I thought that I spelled remove() wrong. I decided to copy-paste it. I was expecting it to show me the mixed-up alphabet when I gave the shift number. What happened was that it gave me this error:
Traceback (most recent call last): File "main.py", line 17, in <module> encrypt("Hello", "9") File "main.py", line 14, in encrypt alphabet = alphabet.remove(0) AttributeError: 'NoneType' object has no attribute 'remove'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道我是否理解你真正想要做什么,但是如果你想删除列表字母表中的第一个对象,那么你应该这样写:
字母表.删除(字母表[0])
我不知道我是否对你有帮助,但也许:D
I dont know if I understood what you really wanted to do, but if you want to remove first object in list alphabet, then you should write it like this:
alphabet.remove(alphabet[0])
Idk if i helped you but maybe :D