[Tutor] Can't figure out syntax error

ZIYAD A. M. AL-BATLY zamb at saudi.net.sa
Fri Jun 10 03:32:19 CEST 2005

On Thu, 2005-06-09 at 18:16 -0600, as.20.schellenberg at spamgourmet.com
> Hi there,
> I'm in the process of learning Python, and need some help deciphering 
> the reason why the following code doesn't work:
>     int(num) = int(num) / 2  # this is integer division, so we truncate the decimal part
Here's your problem!  "int(num)" will try to interpret "num" as an
integer and return that (if possible) as an "int" object, but you're
trying to assign it to the value of "int(num)/2" which doesn't make

What you want, probably, is:
	num = int(num) / 2

Here, "num" will be assigned the value (object actually) of the
resulting of "int(num)/2" which will be an object of type "int".


More information about the Tutor mailing list