Вопрос

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