0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング「2 で何回割れる? Python3編」

Last updated at Posted at 2022-11-23

https://paiza.jp/works/mondai/loop_problems2/loop_problems2__div_two
私の回答

n = int(input())
ans = 0
while n % 2 == 0:
    n = n / 2
    ans += 1
print(ans)

模範解答

N = int(input())

div_count = 0
while True:
    if N % 2 == 0:
        N //= 2
        div_count += 1
    else:
        break

print(div_count)

模範解答はwhileの中でTrueとかbreakを使っていました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?