[Tutor] Can't figure out syntax error
Dan Schellenberg
schellenberg at gmail.com
Fri Jun 10 03:42:59 CEST 2005
Phew -- thanks, Ziyad. That did the trick all right. In my
frustration to figure out the problem, I just began explicitly
type-casting as many variables as I could, and missed the fact that I
had done the same to this as well.
Thanks again,
Dan
On 9-Jun-05, at 7:32 PM, ZIYAD A. M. AL-BATLY - zamb at saudi.net.sa wrote:
> On Thu, 2005-06-09 at 18:16 -0600, as.20.schellenberg at spamgourmet.com
> wrote:
>> Hi there,
>>
>> I'm in the process of learning Python, and need some help deciphering
>> the reason why the following code doesn't work:
> <snip>
>> 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
> sense!
>
> 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".
>
> Ziyad.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list