Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
与えられたエラーの行は次のとおりです。
letter = chr(input('Enter a letter')).lower()
そして、私が受け取る出力は次のとおりです。
TypeError: an integer is required
私が入れていないものはありますか?私は chr() を持っているので、任意の1文字が必要だと思います。
chr()整数が必要ですinput()が、文字列を返します。chr()呼び出しを削除するだけです:
chr()
input()
letter = input('Enter a letter').lower()
入力を 1 文字だけに制限したい場合は、スライスを使用します。
letter = input('Enter a letter')[:1].lower()
Python には「単一文字」タイプがありません。
chr()整数コードポイントを (1 文字の) 文字列に変換するためにのみ使用されます。
>>> chr(65) 'A'