Why Python don't accept 03 as a number?

Cameron Simpson cs at cskk.id.au
Sat Dec 8 00:00:02 EST 2018


On 07Dec2018 20:24, Jach Fong <jfong at ms4.hinet.net> wrote:
>Ian at 2018/12/8 UTC+8 AM11:28:34 wrote:
>> What is it exactly that you're trying to accomplish with this? Perhaps
>> there's a better way than using eval.
>
>This problem comes from solving a word puzzle,
>    ab + aa + cd == ce
>Each character will be translate to a digit and evaluate the correctness,
>    03 + 00 + 15 == 18

Then you should be evaluating the digits and assembling values from 
them. Not trying to shoehorn a string through something that _might_ 
accept this string and do what you want. In Python 2 it will accept your 
string and not do what you want; at least in Python 3 it doesn't accept 
your string.

My point here is that the structure of your puzzle doesn't map directly 
into a naive python statement, and you shouldn't be pretending it might.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list