使用字典来解决

while True:
    try:
        n = input()
    except:
        break
    if n.isnumeric():
        ...
    else:
        dic = {}
        for c in n:
            if dic.get(c):
                dic[c] += 1
            else:
                dic[c] = 1
        num_list = sorted(dic.values(), reverse=True)		# 对字典的值进行排序,从大到小
        beautiful = 26
        sum_beau = 0
        for num in num_list:
            sum_beau += num * beautiful
            beautiful -= 1		# 漂亮值每次减少1
        print(sum_beau)