EDIT: My first "real" python program: pycalc
While working in python, when I try to run a module in the python shell (dled off python.org), I will get an error "IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.". This occurs even with all firewalls off, help please =(
[Edited by - kevtimc on September 7, 2006 6:36:47 PM]
Just to make sure, did you disable the standard windows firewall, in your security center. It is on by default...
Greetings.
Greetings.
Or at the very least, allow IDLE to go through. Sockets connecting to localhost are a common way to do IPC.
Quote:Original post by Limitz
Just to make sure, did you disable the standard windows firewall, in your security center. It is on by default...
Greetings.
Yeah I disabled it.
Quote:Original post by kevtimc
Yeah I disabled it.
Well, in that case you need to check whether you have a runaway python subprocess left behind by a previous session. Check your process list and kill off any python.exe you see there.
Quote:Original post by FrunyQuote:Original post by kevtimc
Yeah I disabled it.
Well, in that case you need to check whether you have a runaway python subprocess left behind by a previous session. Check your process list and kill off any python.exe you see there.
I think that might have been my problem, with that being said here's my first "real" python program, pycalculator:
def displaywelcome(): print "-----------------------------------" print "|_________________________________|" print "|_________________________________|" print "|Welcome to the python calculator!|" print "|_________________________________|" print "| |" print "|---------------------------------|" print "| |" print "| ------- ------- ------- |" print "| | 9 | | 8 | | 7 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| | 6 | | 5 | | 4 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| | 3 | | 2 | | 1 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| |Enter| |Clear| | Quit | |" print "| ------- ------- ------- |" print "|_________________________________|"def updatedisplay(number): print "-----------------------------------" print "|_________________________________|" print "|_________________________________|" print "| ",number, " |" print "|_________________________________|" print "| |" print "|---------------------------------|" print "| |" print "| ------- ------- ------- |" print "| | 9 | | 8 | | 7 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| | 6 | | 5 | | 4 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| | 3 | | 2 | | 1 | |" print "| ------- ------- ------- |" print "| ------- ------- ------- |" print "| |Enter| |Clear| | Quit | |" print "| ------- ------- ------- |" print "|_________________________________|"displaywelcome()number1 = input("Please enter a number")updatedisplay(number1)operation = raw_input("What operand do you wish to use? (addition, subtraction, multiplication, or division)")if operation != "addition" and operation != "subtraction" and operation != "multiplication" and operation != "division": print "Please enter one of the valid choices" operation = raw_input("What operand do you wish to use? (addidtion, subtraction, multiplication, or division)")number2 = input("Please enter the last number")updatedisplay(number2)if operation == "addition": answer = number1 + number2elif operation == "subtraction": answer = number1 - number2elif operation == "multiplication": answer = number1 * number2elif operation == "division": answer = number1 / number2print "Answer:"updatedisplay(answer)
The error check is primitive because I haven't learned about loops yet, but its a calculator nonetheless.
hey im learning python too. send me a pm if you want to exchange IM screen names. We can bounce ideas off each other if you'd like. everyone else is doing the whole c++ thing.
Looks reasonable. You can probably change this line:
if operation != "addition" and operation != "subtraction" and operation != "multiplication" and operation != "division"
To this line:
if operation not in ("addition", "subtraction", "multiplication", "division"):
if operation != "addition" and operation != "subtraction" and operation != "multiplication" and operation != "division"
To this line:
if operation not in ("addition", "subtraction", "multiplication", "division"):
Although I think this might be a little advanced for you right now, it never hurts to check out what the language can really do. You can substitute the long 'if' chains:
with:
Basically, we create a dictionary that stores lambdas(think of them as unnamed functions defined on-the-fly). We can then access the desireable operation using the string "operation" as key.
if operation == "addition": answer = number1 + number2elif operation == "subtraction": answer = number1 - number2elif operation == "multiplication": answer = number1 * number2elif operation == "division": answer = number1 / number2
with:
operations={'addition':lambda x,y: x+y, 'subtraction':lambda x,y: x-y, 'multiplication':lambda x,y: x*y, 'division':lambda x,y: x/y}answer=operations[operation](num1,num2)
Basically, we create a dictionary that stores lambdas(think of them as unnamed functions defined on-the-fly). We can then access the desireable operation using the string "operation" as key.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement