encrypted = ""
for x in strng:
indx = (ord(x) + key) % 256
if indx > 126:
indx = indx - 95
encrypted = encrypted + chr(indx)
return encrypted
After Change
def encrypt(input_string: str, key: int) -> str:
result = ""
for x in input_string:
if not x.isalpha():
result += x
elif x.isupper():
result += chr((ord(x) + key - 65) % 26 + 65)