[Tutor] enhanced subtration in an exponent

Danny Yoo danny.yoo at gmail.com
Tue Apr 21 09:41:15 CEST 2015


On Apr 21, 2015 12:24 AM, "Jim Mooney" <cybervigilante at gmail.com> wrote:
>
> Why does the compiler choke on this? It seems to me that the enhanced
> subtraction resolves to a legitimate integer in the exponent, but I get a
> syntax error:
>
> B = '11011101'
> sum = 0
> start = len(B)
> for char in B:
>     sum += int(char) * 2**(start -= 1) ## syntax error

Assignment is a statement.  In Python,  statements can't be composed.  In
the last line, it looks like you're trying to do two assignments, in
incrementing 'sum' and decrementing 'start'.  Try separating that into two
separate statements.


More information about the Tutor mailing list