Why Python don't accept 03 as a number?

Chris Angelico rosuav at gmail.com
Mon Dec 10 05:03:35 EST 2018


On Mon, Dec 10, 2018 at 9:01 PM Antoon Pardon <antoon.pardon at vub.be> wrote:
>
> On 8/12/18 06:00, Cameron Simpson 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.
> >
> > 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.
>
> How do you figure? As far as I understand he is trying to solve this kind of puzzle:
>
>     SEND
>     MORE
>  +  ————
>    MONEY
>
> Where every letter is to be replaced by a digit in such a way that the sum checks out. Sure trying to
> solve this by starting with the string: "SEND + MORE == MONEY" and doing replaces until eval comes up
> with true is not very sofisticated but I wouldn't call it shoehorning either.
>

Considering that, in a problem of that description, neither S nor M
may represent zero, I don't think there's a problem here.

ChrisA


More information about the Python-list mailing list