Python 3.7 Bug
Terry Reedy
tjreedy at udel.edu
Mon Mar 25 15:29:23 EDT 2019
On 3/25/2019 8:14 AM, Bassam Abdul-Baki wrote:
> Greetings,
>
> In the following code, there's a bug on certain parameters.
>
> ----------
>
> def per(n, steps = 0):
> digits = [int(i) for i in str(n)]
> result = 1
> for j in digits:
> result *= j
> steps += 1
> print(steps, result, sep=" - ")
> if result == 0:
> print(result, str(result), len(str(result)), sep=" - ")
If result is 0, then this just prints useless 0 - 0 - 1
> if len(str(result)) == 1:
> print(" --- DONE ---")
> return "DONE"
> else:
> per(result, steps)
This function, properly written, was recently the subject of a youtube
math video. The largest known # of steps is 11. Did you get it from
there?
> What the program does:
> If I run per(X) and X is a multiple of 10, I should end up with 0 in a
> finite amount of steps.
>
> The problem:
> If I run per(54), I do not get 'DONE' printed through the return
> statement. WRONG!
>
> If I run per(20), I do get 'DONE' printed through the return statement.
> CORRECT!
>
> 20, 30, etc. are correct. 25, 45, etc. are not.
>
> Is this a bug?
>
> Thanks,
> Bassam
>
--
Terry Jan Reedy
More information about the Python-list
mailing list