[Tutor] hi...

Alan Gauld 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.)

Thus

print suma(a,b)

would show the result.

Or as WW said you could store the result in a variable called total

def suma(no1,no2):
    total=no1+no2
    return total

print 'hola'
opcion=input()    # could replace with: opcion = input("hola\n")
if opcion==1:
   print 'suma'
   a=input()       # its good to give a prompt string of some kind
   b=input()
   print suma(a,b)

>>> total
...
> 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.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list