Q. Write a function called shift_string that takes a string and an integer n as parameters and returns a new string with every letter of the string shifted by the n alphabets. It should also work for negative alphabets in reverse order.
So far, I have come up with this:
usr_input=input('Please enter string: ')
n=input('enter shifts: ')
encryption= ""
def shift_string(usr_input,n):
for i in usr_input:
if i.isupper():
i_unicode=ord(i) #find position
i_index=i_unicode-ord('A')
new_index= (i_index + n)
new_unicode= new_index +ord('A') #to perform shift
new_character=chr(new_unicode)
encryption= encryption+new_character #to append string
else:
encryption=encryption+i #for non-uppercase
print('Encrypted text is',encryption)
At encryption= encryption+new_character I am getting the error:
"Local variable 'encryption' defined in enclosing scope on line 23 referenced before assignment...(pyflakes E)"