0

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'
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sutapa
  • 1
  • Change `alphabet = alphabet.reverse()` to `alphabet.reverse()` – eyllanesc Mar 21 '22 at 17:02
  • Also, change `alphabet = alphabet.remove(0)` to `alphabet.remove(0)`, and change `alphabet = alphabet.insert(0, y)` to `alphabet.insert(0, y)`. These three methods (`reverse`, `remove` and `insert`) always return `None` because they are meant to be used as in-place operations. – Paul M. Mar 21 '22 at 17:06

1 Answers1

0

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