Page 1 of 1

i tried to make a encryption text program but as i put it to work i get value error can someone help me on the problem

Posted: Sun Dec 10, 2023 10:42 am
by yas34234
so what the program does is bring the text letter and by reference to (a to z) alphabet list shift the letter to a different order
number in the alphabet and so encrypting the text {if you have any tips on how to present my questions better thats well appreciated also }
now here is the code :

Code: Select all

alphabets = ['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','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']
directin = input("choose the process as 'encrypt' or 'decrept' in the function\n " )
text = input('enter youre text :\n').lower()
shift= int(input('enter the shift amount:\n'))
def encrypt(plain_text,shift_amount):
    ciphar_text = ""
    for letter in plain_text :
        position = alphabets.index(letter)
        new_position = position + shift_amount
        new_letter = alphabets[new_position]
        ciphar_text += new_letter
    print(f'youre encoded text is {ciphar_text}')
encrypt(plain_text=text , shift_amount=shift)

and the erorr is :
position = alphabets.index(letter)
^^^^^^^^^^^^^^^^^^^^^^^
ValueError: ' ' is not in list
what does it mean the value is not in the list why should even be in a list isnt the job of position line to make letters once at a time and than in the end add it to the new_letter line as a string part ?