无法使用remove()

发布于 2025-01-15 23:35:55 字数 1096 浏览 5 评论 0原文

我正在应对制作凯撒密码编码器的挑战。当我遇到这个无法修复的错误时,我正在修复一些错误。请帮助解决这个问题。哦。这是代码。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2025-01-22 23:35:55

我不知道我是否理解你真正想要做什么,但是如果你想删除列表字母表中的第一个对象,那么你应该这样写:
字母表.删除(字母表[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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文