0
0

More than 1 year has passed since last update.

Paizaラーニング 「けた数の測定 Python3編」

Last updated at Posted at 2022-11-18

https://paiza.jp/works/mondai/conditions_branch/conditions_branch__complex_step1
けた数の測定なので、単純にlen関数を使えば良いのかと思ったので、以下のように回答しました。
しかし、条件分岐メニューの問題集だったので、模範解答は条件分岐が使われていました。

私の回答

n=input()
print(len(n))

模範回答

n = int(input())

if n <= 9:
    print(1)
elif n <= 99:
    print(2)
else:
    print(3)
  • Nのけた数を出力します。
  • Nの大きさで以下のように場合わけします。
    1. Nが 9 以下の場合、答えは 1 です。
    2. Nが 10 以上 99 以下の場合、答えは 2 です。
    3. Nが 100 以上 999 以下の場合、答えは 3 です。
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