質問

The line of error given is:

letter = chr(input('Enter a letter')).lower()

and the output I recieve is:

TypeError: an integer is required

Is there something that I didn't put? I think since I have chr() it should require any single character.

役に立ちましたか?

解決

chr() requires an integer, but input() returns a string. Just remove the chr() call:

letter = input('Enter a letter').lower()

If you wanted to limit the input to just one character, use slicing:

letter = input('Enter a letter')[:1].lower()

Python doesn't have a 'single character' type.

chr() is only used to turn an integer code point into a (single character) string:

>>> chr(65)
'A'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top