| | |
Number 1 most possible frustrating situation
Thread Solved |
Okay, the encryption algorithm idea was stupid. But I still made an encryption program. I got the absolute most possible frustrating situation. The program doesn't work in the console window. It spits out a giant error (probably recursion judging how many errors it got), but it DOES work in IDLE. So the only way to fix it is manually see the error, which I've tried to do again and again with no success. So, the error comes after you input the message. So here's the code:
Help would GREATLY be appreciated.
Python Syntax (Toggle Plain Text)
import os import random if os.name == "nt": os.system("color 48") os.system("title Encryptor/Decryptor") def clear(): os.system("cls") else: def clear(): os.system("clear") def menu(): clear() print ("") print ("Encryptor/Decryptor") print ("-------------------") print ("1) Encrypt Message ") print ("2) Decrypt Message ") print ("-------------------") menu_choice = input ("Choose one: ") if menu_choice != "1": if menu_choice != "2": clear() print ("") print ("Please type a valid choice!") input () menu() if menu_choice == "1": encrypt() if menu_choice == "2": decrypt() def encrypt(): clear() print ("") print ("------------------------------------") print ("1) Use computer generated number key") print ("2) Manually key ") print ("------------------------------------") encrypt_choice = input ("Choose one: ") if encrypt_choice == "1": key = list(str(random.random()).split(".")[1]) else: clear() print ("") key = list(str(input("Please type key: "))) show = "" while 1: clear() print ("") print (show) print ("Type S to show key, H to hide key ") print ("Type R to change key ") print ("-----------------------------------") message = list(input ("Please type a message to be encrypted: ")) if "".join(message).lower() == "s": show = str("Key is: " + str("".join(key))) continue if "".join(message).lower() == "r": encrypt() if "".join(message).lower() == "h": show = "" continue break while len(key) < len(message): key += key spaces = 0 encrypt_list = [] shift = 1 for loop in range((len(message))): shift += 1 if str(message[loop]) == ' ': spaces += 1 else: if str(message[loop]) == ' ': spaces += 1 '' if str(message[loop]) != ' ': if str(message[loop]) != ' ': if str(message[loop]) == str(key[loop-spaces]): encrypt_list.append(message[loop]) else: if (shift % 2) == 0: loop_ord = str(chr(ord(key[loop-spaces])+ord(message[loop]))) else: if ord(str(message[loop])) < ord(str(key[loop-spaces])): loop_ord = "9u" + str(chr(ord(key[loop-spaces])-ord(message[loop]))) else: loop_ord = chr(ord(message[loop])-ord(key[loop-spaces])) encrypt_list.append(loop_ord) print ("") print ("Encrypted message is: ", "".join(encrypt_list)) if show == "": print ("") ask = input ("Show key before leaving(Y/N): ") if ask.lower() == "y": print ("") print ("Key is: " + str("".join(key))) input () menu() def decrypt(): menu() menu()
Help would GREATLY be appreciated.
Last edited by AutoPython; 26 Days Ago at 10:58 pm.
To P(ython), or not to P(ython)
0
#2 25 Days Ago
Well already I see one problem. You are using the input() function instead of using raw_input(). Input only receives int data types. Though when you try to compare the user input to a valid choice you are comparing it to a string. Use raw_input() because it reads in strings instead and this should solve that problem.
Edit: Also you need not use so many print statements. You can print lines like so.
Edit: Also you need not use so many print statements. You can print lines like so.
python Syntax (Toggle Plain Text)
# using triple quoted strings print '''What would you like to do? 1) This 2) Or this 3) Exit '''
Last edited by ShadyTyrant; 25 Days Ago at 12:57 pm. Reason: Added more info
0
#3 25 Days Ago
•
•
•
•
You are using the input() function instead of using raw_input().
input has been replaced by raw_input )EDIT: Additionally, I tried his code (after modifying it to be Python 2.X compliant) and it worked for the most part. To the OP: could you explain the error in more detail and provide some traceback?
Last edited by jlm699; 25 Days Ago at 1:26 pm.
0
#5 25 Days Ago
I want to encourage posters to give us the version of Python they are using. Otherwise the rest of us have to assume and ask. Python25 for instance allows you to use the print statement or the print() function. So using the fact that print() was used is not necessarily indicative of the a Python3 application.
Not quite sure what the OP means with it DOES work in IDLE, unless IDLE uses Python3 and his system default on saved files is still Python2.
Not quite sure what the OP means with it DOES work in IDLE, unless IDLE uses Python3 and his system default on saved files is still Python2.
Last edited by vegaseat; 24 Days Ago at 5:07 pm.
May 'the Google' be with you!
0
#6 25 Days Ago
No, system default for files and IDLE are the same, I can't explain the error to you because the console window closes before I can see it, but IDLE gives no error.
Do you think this isn't my code? How could I make code like this if I didn't even know what function to use.
I hope you understand my problem now, I don't know why every thing is working in idle, but not the console.
•
•
•
•
Well already I see one problem. You are using the input() function instead of using raw_input().
I hope you understand my problem now, I don't know why every thing is working in idle, but not the console.
Last edited by AutoPython; 25 Days Ago at 5:12 pm.
To P(ython), or not to P(ython)
0
#7 25 Days Ago
Try this trick (I'm assuming you're using Windows)
1) Open up a terminal (command prompt window) 2) Type/find path to Python executable This should get you running your python script inside a persistent window that won't close itself. And example command would be:
1) Open up a terminal (command prompt window)
Python Syntax (Toggle Plain Text)
Ctrl+R -> cmd -> [Enter]
Python Syntax (Toggle Plain Text)
dir C:\Py* -> [Enter] # You should see the folder name for your Python install (I'm guessing it's Python30 C:\Python30\python.exe -> Drag-and-drop your python script to the command prompt window (where you're typing this stuff), which should auto-insert the full path to your python script -> [Enter]
Python Syntax (Toggle Plain Text)
C:\> C:\Python25\python.exe "C:\Documents and Settings\Administrator\Desktop\em_test.py"
Last edited by jlm699; 25 Days Ago at 5:28 pm.
0
#8 25 Days Ago
I wasn't trying to say you didn't write the code. It was just an error that popped up for me when I tried to run the code. Though jlm699 corrected me already. Anyways since the console is closing before you can see the error, open a console first and run the program from the command line. That way when the program throws the error the console wont close.
0
#9 25 Days Ago
Thank you for the help. But the problem is solved, it wasn't the encrypting part (thank goodness), but when it attempted to print some of the unicode characters with 2 symbols it couldn't. Still don't know how IDLE found a way around it.
Last edited by AutoPython; 25 Days Ago at 9:46 pm.
To P(ython), or not to P(ython)
0
#10 25 Days Ago
If you declared the encoding at the beginning of your program the same way that IDLE does, it would have worked I believe?
![]() |
Similar Threads
- how do i figure out if a string has a number in it? (C)
- My Black Screen of death. (Troubleshooting Dead Machines)
- Flash Player stop working since Ad-aware (Web Browsers)
- Session time limit (DaniWeb Community Feedback)
- Runtime Error& App Error - Using Adobe Premiere Pro - I am a newbie! First post (Windows NT / 2000 / XP)
- Validating a double type variable to ensure it is an integer (C)
- text orientation (HTML and CSS)
Other Threads in the Python Forum
- Previous Thread: Vpython error won't run any programs
- Next Thread: OS X default save path
| Thread Tools | Search this Thread |
advanced aliased bash beginner bits calling casino changecolor clear command convert corners count csv cturtle cursor def definedlines dictionary digital dynamic dynamically event events examples external file float format frange function google gui hints homework i/o iframe import info input jaunty java line linux list lists loop matching mouse multiple number numbers obexftp output parsing path port prime programming projects py py2exe pygame pygtk python random rational raw_input recursion return scrolledtext signal singleton skinning stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip web-scrape whileloop word wxpython






