Code Fix

Pythonエラー 練習問題 117問(全問無料)

コンパイルエラー・実行時エラー・ロジックの誤りを、空欄補充で直す練習問題です。登録不要でその場で解けます。エラーメッセージで絞り込めます。

出題モード

このモードで始める

選んだモードは次の問題への移動にも適用されます。記録は端末内にのみ保存されます。

すべての問題

エラー難易度種別
IndentationError: expected an indented block の原因と直し方 #1 初級コンパイル
IndentationError: expected an indented block の原因と直し方 #2 初級コンパイル
IndentationError: expected an indented block の原因と直し方 #3 初級コンパイル
SyntaxError: expected ':' の原因と直し方 #1 初級コンパイル
SyntaxError: expected ':' の原因と直し方 #2 初級コンパイル
SyntaxError: expected ':' の原因と直し方 #3 初級コンパイル
TabError: inconsistent use of tabs and spaces の原因と直し方 #1 初級コンパイル
TabError: inconsistent use of tabs and spaces の原因と直し方 #2 初級コンパイル
TabError: inconsistent use of tabs and spaces の原因と直し方 #3 初級コンパイル
NameError: name 'x' is not defined の原因と直し方 #1 初級実行時
NameError: name 'x' is not defined の原因と直し方 #2 初級実行時
NameError: name 'x' is not defined の原因と直し方 #3 初級実行時
SyntaxError: Missing parentheses in call to 'print' の原因と直し方 #1 初級コンパイル
SyntaxError: Missing parentheses in call to 'print' の原因と直し方 #2 初級コンパイル
SyntaxError: Missing parentheses in call to 'print' の原因と直し方 #3 初級コンパイル
SyntaxError: unterminated string literal の原因と直し方 #1 初級コンパイル
SyntaxError: unterminated string literal の原因と直し方 #2 初級コンパイル
SyntaxError: unterminated string literal の原因と直し方 #3 初級コンパイル
SyntaxError: '(' was never closed の原因と直し方 #1 初級コンパイル
SyntaxError: '(' was never closed の原因と直し方 #2 初級コンパイル
SyntaxError: '(' was never closed の原因と直し方 #3 初級コンパイル
ZeroDivisionError: division by zero の原因と直し方 #1 初級実行時
ZeroDivisionError: division by zero の原因と直し方 #2 初級実行時
ZeroDivisionError: division by zero の原因と直し方 #3 初級実行時
TypeError: can only concatenate str (not "int") to str の原因と直し方 #1 初級実行時
TypeError: can only concatenate str (not "int") to str の原因と直し方 #2 初級実行時
TypeError: can only concatenate str (not "int") to str の原因と直し方 #3 初級実行時
TypeError: '>' not supported between instances の原因と直し方 #1 初級実行時
TypeError: '>' not supported between instances の原因と直し方 #2 初級実行時
TypeError: '>' not supported between instances の原因と直し方 #3 初級実行時
SyntaxError: invalid syntax(if x = 5:)の原因と直し方 #1 初級コンパイル
SyntaxError: invalid syntax(if x = 5:)の原因と直し方 #2 初級コンパイル
SyntaxError: invalid syntax(if x = 5:)の原因と直し方 #3 初級コンパイル
NameError: Did you mean 'True'? の原因と直し方 #1 初級実行時
NameError: Did you mean 'True'? の原因と直し方 #2 初級実行時
NameError: Did you mean 'True'? の原因と直し方 #3 初級実行時
IndexError: list index out of range の原因と直し方 #1 初級実行時
IndexError: list index out of range の原因と直し方 #2 初級実行時
IndexError: list index out of range の原因と直し方 #3 初級実行時
AttributeError: object has no attribute 'length' の原因と直し方 #1 初級実行時
AttributeError: object has no attribute 'length' の原因と直し方 #2 初級実行時
AttributeError: object has no attribute 'length' の原因と直し方 #3 初級実行時
AttributeError: 'NoneType' object has no attribute の原因と直し方 #1 中級実行時
AttributeError: 'NoneType' object has no attribute の原因と直し方 #2 中級実行時
AttributeError: 'NoneType' object has no attribute の原因と直し方 #3 中級実行時
AttributeError: object has no attribute(メソッド名タイプミス)の原因と直し方 #1 中級実行時
AttributeError: object has no attribute(メソッド名タイプミス)の原因と直し方 #2 中級実行時
AttributeError: object has no attribute(メソッド名タイプミス)の原因と直し方 #3 中級実行時
KeyError の原因と直し方 #1 中級実行時
KeyError の原因と直し方 #2 中級実行時
KeyError の原因と直し方 #3 中級実行時
ValueError: invalid literal for int() with base 10 の原因と直し方 #1 中級実行時
ValueError: invalid literal for int() with base 10 の原因と直し方 #2 中級実行時
ValueError: invalid literal for int() with base 10 の原因と直し方 #3 中級実行時
TypeError: missing 1 required positional argument の原因と直し方 #1 中級実行時
TypeError: missing 1 required positional argument の原因と直し方 #2 中級実行時
TypeError: missing 1 required positional argument の原因と直し方 #3 中級実行時
TypeError: takes N positional arguments but M were given の原因と直し方 #1 中級実行時
TypeError: takes N positional arguments but M were given の原因と直し方 #2 中級実行時
TypeError: takes N positional arguments but M were given の原因と直し方 #3 中級実行時
TypeError: missing 1 required positional argument: 'self' の原因と直し方 #1 中級実行時
TypeError: missing 1 required positional argument: 'self' の原因と直し方 #2 中級実行時
TypeError: missing 1 required positional argument: 'self' の原因と直し方 #3 中級実行時
UnboundLocalError: cannot access local variable の原因と直し方 #1 中級実行時
UnboundLocalError: cannot access local variable の原因と直し方 #2 中級実行時
UnboundLocalError: cannot access local variable の原因と直し方 #3 中級実行時
TypeError: 'str' object does not support item assignment の原因と直し方 #1 中級実行時
TypeError: 'str' object does not support item assignment の原因と直し方 #2 中級実行時
TypeError: 'str' object does not support item assignment の原因と直し方 #3 中級実行時
// と / の違い(整数除算と真の除算) #1 中級ロジック
// と / の違い(整数除算と真の除算) #2 中級ロジック
// と / の違い(整数除算と真の除算) #3 中級ロジック
TypeError: 'tuple' object does not support item assignment の原因と直し方 #1 中級実行時
TypeError: 'tuple' object does not support item assignment の原因と直し方 #2 中級実行時
TypeError: 'tuple' object does not support item assignment の原因と直し方 #3 中級実行時
関数内でグローバル変数を更新できない(globalキーワード忘れ) #1 中級ロジック
関数内でグローバル変数を更新できない(globalキーワード忘れ) #2 中級ロジック
関数内でグローバル変数を更新できない(globalキーワード忘れ) #3 中級ロジック
剰余演算 % の符号がJavaと異なる理由 #1 中級ロジック
剰余演算 % の符号がJavaと異なる理由 #2 中級ロジック
剰余演算 % の符号がJavaと異なる理由 #3 中級ロジック
f忘れでf文字列が展開されない #1 中級ロジック
f忘れでf文字列が展開されない #2 中級ロジック
f忘れでf文字列が展開されない #3 中級ロジック
range()の範囲指定でループが1回分ずれる #1 中級ロジック
range()の範囲指定でループが1回分ずれる #2 中級ロジック
range()の範囲指定でループが1回分ずれる #3 中級ロジック
可変デフォルト引数が呼び出しをまたいで共有される #1 上級ロジック
可変デフォルト引数が呼び出しをまたいで共有される #2 上級ロジック
可変デフォルト引数が呼び出しをまたいで共有される #3 上級ロジック
イテレート中のリスト変更で要素が飛ばされる #1 上級ロジック
イテレート中のリスト変更で要素が飛ばされる #2 上級ロジック
イテレート中のリスト変更で要素が飛ばされる #3 上級ロジック
RuntimeError: dictionary changed size during iteration の原因と直し方 #1 上級実行時
RuntimeError: dictionary changed size during iteration の原因と直し方 #2 上級実行時
RuntimeError: dictionary changed size during iteration の原因と直し方 #3 上級実行時
= で複製したつもりが同じリストを指している(浅いコピー) #1 上級ロジック
= で複製したつもりが同じリストを指している(浅いコピー) #2 上級ロジック
= で複製したつもりが同じリストを指している(浅いコピー) #3 上級ロジック
is と == の違い(小さい整数キャッシュで「たまたま動く」) #1 上級ロジック
is と == の違い(小さい整数キャッシュで「たまたま動く」) #2 上級ロジック
is と == の違い(小さい整数キャッシュで「たまたま動く」) #3 上級ロジック
RecursionError: maximum recursion depth exceeded の原因と直し方 #1 上級実行時
RecursionError: maximum recursion depth exceeded の原因と直し方 #2 上級実行時
RecursionError: maximum recursion depth exceeded の原因と直し方 #3 上級実行時
0.1 + 0.2 が 0.3 にならない理由 #1 上級ロジック
0.1 + 0.2 が 0.3 にならない理由 #2 上級ロジック
0.1 + 0.2 が 0.3 にならない理由 #3 上級ロジック
クラス属性がインスタンス間で共有される #1 上級ロジック
クラス属性がインスタンス間で共有される #2 上級ロジック
クラス属性がインスタンス間で共有される #3 上級ロジック
except: だけで書くと本当のバグまで隠れる #1 上級ロジック
except: だけで書くと本当のバグまで隠れる #2 上級ロジック
except: だけで書くと本当のバグまで隠れる #3 上級ロジック
0や空文字列を「値が無い」と誤判定してしまう #1 上級ロジック
0や空文字列を「値が無い」と誤判定してしまう #2 上級ロジック
0や空文字列を「値が無い」と誤判定してしまう #3 上級ロジック
広告
広告スロット(未設定)

エラーの種類について

Pythonのエラーは大きく3種類に分かれます。構文エラーはコードを解析する段階で検出されるもので、実行が一切始まりません。SyntaxErrorやIndentationErrorが代表例です。実行時エラーは構文としては正しいものの、実行中に投げられる例外で、NameErrorやTypeErrorが代表例です。ロジックの誤りはどちらのエラーも出ませんが結果が期待と違うもので、リストのインデックスの数え間違いなどが典型です。

最も発見が遅れるのは3つ目です。このサイトではロジックの誤りも問題に含めており、コンソール表示が赤ではなく琥珀色になります。

初級から順に解く

広告
広告スロット(未設定)