What is wrong with his code? It is not running, please check it.
def encrypt(message,shift):
encrypted_message = " "
lst=[]
lst.extend(message)
for x in lst:
if(x.isalpha()):
if(ord(x)<= 90 and (ord(x)+shift) > 90):
new =(ord(x)+shift)- 90
encrypted_message += chr(64+new)
elif(ord(x)<= 122 and (ord(x)+shift) > 122):
new =(ord(x)+shift)- 122
encrypted_message += chr(96+new)
else:
encrypted_message += chr(ord(x) + shift)
else:
encrypted_message+=x
print(encrypted_message)
def main():
message=input()
shift=int(input())
while(shift<0 or shift>25):
print("Invalid shift")
shift=int(input())
encrypt(message,shift)
main()
def encrypt(message,shift):
encrypted_message = ""
for x in message:
if(x.isalpha()):
if(ord(x) <= 90 and (ord(x) + shift) > 90):
new = (ord(x) + shift) - 90
encrypted_message += chr(64 + new)
elif(ord(x) <= 122 and (ord(x) + shift) > 122):
new =(ord(x) + shift) - 122
encrypted_message += chr(96 + new)
else:
encrypted_message += chr(ord(x) + shift)
else:
encrypted_message += x
print(encrypted_message)
def main():
message = input()
shift = int(input())
while(shift < 0 or shift > 25):
print("Invalid shift")
shift = int(input())
encrypt(message, shift)
main()
Comments
Leave a comment