入力された数値の桁数を取得してみます。
1. 組み込み関数のlen()を使用する
>>> len(str(1000))
4
2. 数学関数モジュールのmathを使用する
math — Mathematical functions — Python 3.7.17 documentation
>>> import math
>>> int (math.log10(1000) + 1)
4
終わり。
入力された数値の桁数を取得してみます。
>>> len(str(1000))
4
math — Mathematical functions — Python 3.7.17 documentation
>>> import math
>>> int (math.log10(1000) + 1)
4
終わり。