[Tutor] Converting integers into digit sum (Python 3.3.0)

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Mon Dec 9 15:07:34 CET 2013


spir <denis.spir <at> gmail.com> writes:

> 
> On 12/09/2013 02:29 PM, Wolfgang Maier wrote:
> > spir <denis.spir <at> gmail.com> writes:
> >
> >>
> >> Tu sum it up (aha!): you algorithm is the right and only one
> >
> > No, it's not the only one. It's certainly the most obvious one, but there is
> > also the pure numbers approach pointed out by me and Alan.
> 
> You are right in a sense, but this is what int() does, isn't it? So in
another 

Interesting question!
I would assume str() and int() to use a similar algorithm, but I never
looked at their actual implementation, so this is just speculation.
Also, as a general rule I thought one shouldn't rely on implementation
details since they could change (admittedly, quite unlikely for something as
basic as this though).

> sense I thought it is still the same algo, and it was simpler to present
it that 
> way. But I also agree with your point of view.
> 
> Denis

Fair enough.

Best,
Wolfgang





More information about the Tutor mailing list