Why Python don't accept 03 as a number?

Richard Damon Richard at Damon-Family.org
Sat Dec 8 08:18:45 EST 2018


On 12/7/18 11:24 PM, 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
>
For the classic version of that problem, a = 0 is not allowed, since you
never in 'normal' life write number with leading zeros, the alpha-math
problems never have leading zeros either.

As other have said, the work to compute the value yourself rather than
due the text substitution and eval is close to comparable.

-- 
Richard Damon



More information about the Python-list mailing list