Issue
I'm new to coding and have been trying my luck at making a Cesar cipher (by following a youtube video) but keep getting a syntax error. Can anyone help?
Here's the code:
result = ""
message = ""
choice = ""
while choice != 0:
choice = input ("\ndo you want to encrypt or decrypt a message?\nEnter1 to encrypt, 2 to decrypt and 0 to exit. ")
if choice == '1':
message = input ("\nEnter message for encrpytion: ")
for i in range(0, len(message)):
result = result +chr(ord(message)[i] - 2
print (result + ('\n\n' )
result = ''
elif choice == '2':
message = input ("\nEnter message to be decrypted: ")
for i in range (0, len(message)):
result = result + chr(ord(message[i]) + 2)
print (result + '\n\n' )
result = ''
elif choice is != 0:
print ("you have entered an invalid command please try again \n\n")
Solution
You had several syntax errors, this should fix it:
result = ""
message = ""
choice = ""
while choice != '0':
choice = input("\ndo you want to encrypt or decrypt a message?\nEnter1 to encrypt, 2 to decrypt and 0 to exit. ")
if choice == '1':
message = input("\nEnter message for encrpytion: ")
for i in range(0, len(message)):
result += chr(ord(message[i]) - 2)
print(result)
result = ''
elif choice == '2':
message = input ("\nEnter message to be decrypted: ")
for i in range (0, len(message)):
result += chr(ord(message[i]) + 2)
print(result)
result = ''
elif choice == '0':
break
else:
print ("you have entered an invalid command please try again")
Answered By - Merig
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.