Issue
i tried something using python and while the encrypt() function works fine, the decrypt() function doesnt give me any output, not even an error :(
My code:
import os
abc=['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', ' ', '.', ',', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', ':', "'"]
mixed=abc[::-1]
os.system("clear")
def menu():
print "-----------"
print "[1] Encrypt"
print "[2] Decrypt"
print "-----------"
if input(">>> ")==1:
encrypt()
elif input(">>> ")==2:
decrypt()
def encrypt():
os.system('clear')
text=raw_input(">>> ").lower()
text=list(text)
textnew=text
for i in range(len(text)):
textnew[i]=mixed[abc.index(text[i])]
print ''.join(textnew)
menu()
def decrypt():
os.system('clear')
text=raw_input(">>> ").lower()
text=list(text)
textnew=text
for i in range(len(text)):
textnew[i]=abc[mixed.index(text[i])]
print ''.join(textnew)
menu()
menu()
Solution
if input(">>> ")==1:
encrypt()
elif input(">>> ")==2:
decrypt()
You're reading a second input in your elif
. That's why it seems like the first command is being ignored. By the way, input
in Python 2 is unsafe. You should stick with raw_input
(which just returns a string without trying to evaluate it).
command = raw_input(">>> ")
if command=="1":
encrypt()
elif command=="2":
decrypt()
Answered By - khelwood
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.