简体   繁体   中英

an integer is required, chr defined

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM