alan.gauld at btinternet.com
Sun Aug 24 16:22:42 CEST 2008
"Alberto Perez" <betopm at live.com.mx> wrote
>. How clear the screen of GUI python interactive????
bhaaaluu answered that
> and which is the difference between interactive mode
> and not interactive mode????
WW answered that
> because when I run a program in interactive mode,
> the program run very good, but if run in not interactive
> mode not show me error,
How are you running your program in "non interactive mode"
Are you using IDLE or Pythonwin? Or are you running it from
a command window? If you are running it from IDLE are you
creating a new file and typing in the code then saving it
and running it from the menu (or F5 key)?
That's what it looks like...
> but the return of function returns no value
It returns a value but you don't print it.
One big difference between >>> and non interactive mode
is that the >>> prompt prints the values of expressions,
including function calls. Non interacticve mode does
not print these, you have to use print. (This is why in my
tutorial I always use print even in the >>> prompt; because
it avoids this confusion.)
would show the result.
Or as WW said you could store the result in a variable called total
opcion=input() # could replace with: opcion = input("hola\n")
a=input() # its good to give a prompt string of some kind
> name 'total' is not defined>>>
> why this happens???
As the error says total is not defined in your shells namespace.
It only exists within your program. As WW said, it only exists inside
suma() in your code. Thasts why you need to create a "global" level
variable or just print the result of suma() directly.
Author of the Learn to Program web site
More information about the Tutor