[Tutor] declare-define

Lloyd Kvam pythonTutor at venix.com
Fri Oct 15 15:20:36 CEST 2004

On Fri, 2004-10-15 at 02:09, nitt wrote:
> Hi All'
>     Trying to get the following, and yes,tried most everything.
> input("p(1)=")
This creates a prompt for assigning to p(1), BUT it does not actually
save the input.  Also, p(1) is NOT a valid python name.  It calls p with
an argument of 1.  p would likely be a function or a class.

p_1 = input("p_1=")
is a simple rewrite of the line into valid python code.

> input("p(1)=")
This is probably a typo and should become:
p_2 = input("p_2=")

> input("p(3)=")
You know the pattern now.
> a=p(1)*(p(1)*p(2)-1)*(p(3)+1)/(p(1)+1)
a = p_1 * (p_1*p_2-1)*(p_3+1)/(p_1+1)

As you can see, the numbers in the variable names make this equation
hard to read. Names like a,b,c would be easier to separate from the
numbers.  Descriptive names
	(e.g. area = length * width )
are best.

> print int(a) rjust(45)

a should already be an integer.  The things to be printed should be
separated by commas.
print a, p_1, p_2, p_3

I do not know the intent of rjust(45).  The string % operator can be
used to control numeric formats.  It is documented in the Library
Reference Manual.  If you simply wanted more space between a and 45,
print a, "       ", 45

> Keep getting name error,p() not defined and rjust doesn't exist.
> using 234
>                  Appreciate any help given
>                  King regards
>                                       nitt at iprimus.com.au
> ______________________________________________________________________
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
Lloyd Kvam
Venix Corp

More information about the Tutor mailing list