Connecting Tech Pros Worldwide Help | Site Map

very very basic question

aghazalp
Guest
 
Posts: n/a
#1: Apr 2 '06
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

Georg Brandl
Guest
 
Posts: n/a
#2: Apr 2 '06

re: very very basic question


aghazalp wrote:[color=blue]
> 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?[/color]

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
aghazalp
Guest
 
Posts: n/a
#3: Apr 2 '06

re: very very basic question


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

Georg Brandl
Guest
 
Posts: n/a
#4: Apr 2 '06

re: very very basic question


aghazalp wrote:[color=blue]
> 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()[/color]

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

raw_input()

Georg
aghazalp
Guest
 
Posts: n/a
#5: Apr 2 '06

re: very very basic question


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

Larry Bates
Guest
 
Posts: n/a
#6: Apr 2 '06

re: very very basic question


aghazalp wrote:[color=blue]
> 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
>[/color]

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
aghazalp
Guest
 
Posts: n/a
#7: Apr 2 '06

re: very very basic question


WOWWWWWWWW Larry
that was very very smart...it works perfectly =)

Closed Thread