Question

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.

Was it helpful?

Solution

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'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top