中級 › ValueError: invalid literal for int() with base 10 の原因と直し方 › パターン3
ValueError: invalid literal for int() with base 10 の原因と直し方
int()に数字以外の文字を含む文字列を渡したときに出るエラーです。
1 count = int(____) ^ 2 print(count)
Traceback (most recent call last):
File "main.py", line 1, in <module>
count = int("")
^^^^^^^
ValueError: invalid literal for int() with base 10: ''
空欄を埋めて実行を通す
空文字列も数値として解釈できないためValueErrorになります。input()の戻り値をそのまま変換する際に起きやすいです。
次の問題