如何只计算字符串中的字母
你好,
我遇到了一种计算输入字符串中字母字符数量的方法,以及一种计算数字字符数量的方法。我一直在尝试ispha和isdigit字符串方法,但什么也想不出来。到目前为止,我有:
选择 | 换行 | 行号
- def main():
- sentence = input('Enter a sentence: ')
- Stats(sentence)
- def Stats(input):
- print('Total characters:', character(input))
- print('Letters:', letter(input))
- print('Digits:', digit(input))
- def character(input):
- count = 0
- for char in input:
- count += 1
- return (count)
- def letter(input):
- # This is where I'm stuck. Not sure how to use isalpha()
- # to make this work
- def digit(input):
- # here as well, but with the isdigit().