---------- Forwarded message ---------- From: W W <[EMAIL PROTECTED]> Date: Sun, Aug 24, 2008 at 7:17 AM Subject: Re: [Tutor] hi... To: Alberto Perez <[EMAIL PROTECTED]>
On Sun, Aug 24, 2008 at 1:31 AM, Alberto Perez <[EMAIL PROTECTED]> wrote: > I have a problem with python, I'm begginner in python. How clear the > screen of GUI python interactive???? > I'm not really aware of a way, other than to exit and restart. Is there any particular reason you need/want to? > and which is the difference between interactive mode and not interactive > mode???? > interactive mode executes each statement after you write it, for instance: >>> x = 1 >>> x += 1 >>> print x 2 >>> y = x * 2 >>> print x, y 2 4 but if you put this in a file: x = 1 x += 1 print x y = x * 2 print x, y then you run your file and it will output: 2 2 4 > 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, but the return > of function returns no value, this is the source code: > Your problem isn't that the function returns no value, it's that it doesn't work like you think it should. > def suma(no1,no2): > total=no1+no2 > return total > Right here your function returns the value of "total", not the actual variable. > > print 'hola' > opcion=input() > if opcion==1: > print 'suma' > a=input() > b=input() > suma(a,b) > So right here, the line suma(a, b) does nothing for you, but evaluate the total. If you want to print the value, you need to store it in a variable: total = suma(a, b) would work. > > the result of this code is: > > hola > 1 > suma > 5 > 7 > >>> total > Traceback (most recent call last): > File "<pyshell#0>", line 1, in <module> > total > NameError: name 'total' is not defined > >>> > > why this happens??? what I did wrong??? and why run very good in > interactive mode??? thanks for help me and sorry for my bad english, I from > Mexico and I english student. Thank you. > If you've read the above comments, hopefully that explains what you need. In addition, I re-wrote your program to work properly: def suma(no1, no2): total = no1 + no2 return total print 'Hola' opcion = int(raw_input()) if opcion == 1: print 'Suma' a = int(raw_input()) b = int(raw_input()) total = suma (a, b) print total Hope this helps, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor