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の大きさで以下のように場合わけします。
- Nが 9 以下の場合、答えは 1 です。
- Nが 10 以上 99 以下の場合、答えは 2 です。
- Nが 100 以上 999 以下の場合、答えは 3 です。