while True:
    try:
        str1=input()
        set1=set(str1)
        str2=list(set1)
        n=0
        for i in str2:
            if ord(i)>=0 and ord(i)<=127:
                n+=1
        print(n) 
    except:
        break

核心思路

去重后进行统计判断

注意

在C语言中,假设当前字符为c,可以用c+'0'-48之类的直接转换的写法,但Python需要通过函数。

  • ord():转换为码
  • chr():转换为字符