very very basic question

A

aghazalp

hi guys,
this would be the most basic question ever...I am not a programmer but
I am trying to learn programming in python...I was reading John Zelle's
text book and instructed me to make .py file and save it on the desk
top...then it said close the python GUI and double click on the icon of
the I just made and that should run the program...well, the good news
is that it does but when I input a number for calculation and press the
enter key the program closes...Does any one know what the problem is?

thanx a bunch
andy
 
G

Georg Brandl

aghazalp said:
hi guys,
this would be the most basic question ever...I am not a programmer but
I am trying to learn programming in python...I was reading John Zelle's
text book and instructed me to make .py file and save it on the desk
top...then it said close the python GUI and double click on the icon of
the I just made and that should run the program...well, the good news
is that it does but when I input a number for calculation and press the
enter key the program closes...Does any one know what the problem is?

The DOS box closes as soon as the program terminates. To prevent that, add
a call to raw_input() at the end of your script. Python will then prompt you
for input, and therefore the window will stay open.

Georg
 
A

aghazalp

thanx george for the prompt answer... when you say add a call that
means what exactly?...here is the program I was supposed to
write...could you tell me what to add where in this program?

def main():
print "this program is crazy"
x=input ('enter a number betwenen 0 and 1: ')
for i range (10)
x=3.9*x*(1-x)
print x

main()


thanx again
 
G

Georg Brandl

aghazalp said:
thanx george for the prompt answer... when you say add a call that
means what exactly?...here is the program I was supposed to
write...could you tell me what to add where in this program?

def main():
print "this program is crazy"
x=input ('enter a number betwenen 0 and 1: ')
for i range (10)
x=3.9*x*(1-x)
print x

main()

At the very end of the program, that is here, after main(), just insert

raw_input()

Georg
 
A

aghazalp

thanx ...it works great now...you re awesome...the only thing is that
the program only executes once though...I guess I ll have to read up
more anout it but for now that helped me a lot...I appreciated the help
 
L

Larry Bates

aghazalp said:
thanx ...it works great now...you re awesome...the only thing is that
the program only executes once though...I guess I ll have to read up
more anout it but for now that helped me a lot...I appreciated the help

It only executes once because you only call it once.

Your program:

def main():
print "this program is crazy"
x=input ('enter a number betwenen 0 and 1: ')
for i range (10)
x=3.9*x*(1-x)
print x

main()

Change to something like:

def main():
print "this program is crazy"
while 1:
x=input ('enter a number between 0 and 1 [-1 to exit]: ')
if x == -1: break
for i range (10)
x=3.9*x*(1-x)
print x

main()


-Larry Bates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top