on writing a number as 2^s * q, where q is odd

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Wed Nov 29 21:10:26 EST 2023


On 2023-11-29 at 21:44:01 -0300,
Julieta Shem via Python-list <python-list at python.org> wrote:

> How would you write this procedure?
> 
> --8<---------------cut here---------------start------------->8---
> def powers_of_2_in(n):
>   s = 0
>   while "I still find factors of 2 in n...":
>     q, r = divmod(n, 2)
>     if r == 0:
>       s = s + 1
>       n = n // 2
>     else:
>       return s, n
> --8<---------------cut here---------------end--------------->8---

What's wrong with what you have?


More information about the Python-list mailing list