Why Python don't accept 03 as a number?
Grant Edwards
grant.b.edwards at gmail.com
Sat Dec 8 11:49:29 EST 2018
On 2018-12-08, Cameron Simpson <cs at cskk.id.au> wrote:
> 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.
Just to be clear: you do _not_ want to use eval on the string.
If you're not the one who created the string, it might wipe your hard
drive or empty your bank account. If you _are_ the one who created
the string, then generate the desired result instead.
--
Grant
More information about the Python-list
mailing list