PAT (Basic Level) Practice 1002 Python

A = input()
a = 0
for i in A:
    a = a + int(i)

Chinese_dict = {"1": "yi", "2": "er", "3": "san", "4": "si", "5": "wu", "6": "liu",
                "7": "qi", "8": "ba", "9": "jiu", "0": "ling"}

P_str = ""

for i in str(a):
    for key in Chinese_dict.keys():
        if i == key:
            P_str = P_str + Chinese_dict[key] + " " # print(Chinese_dict[key])
print(P_str.rstrip())

你可能感兴趣的:(算法刷题·解)