首页 新闻 会员 周边 捐助

python--1002 写出这个数(PTA)

0
悬赏园豆:20 [已关闭问题] 关闭于 2019-09-17 20:29

请问下这个python代码在pta提交部分正确如何修改?

以下为源码(python新手,请别介意,努力提升中):

# 数字转汉语拼音
def tran(num):
    if num == 0:
        str = 'ling'
        return str
    elif num == 1:
        str = 'yi'
        return str
    elif num == 2:
        str = 'er'
        return str
    elif num == 3:
        str = 'san'
        return str
    elif num == 4:
        str = 'si'
        return str
    elif num == 5:
        str = 'wu'
        return str
    elif num == 6:
        str = 'liu'
        return str
    elif num == 7:
        str = 'qi'
        return str
    elif num == 8:
        str = 'ba'
        return str
    elif num == 9:
        str = 'jiu'
        return str


n = input()
sum = 0  # 记录各数字之和
num = 0  # 读取 sum 每一位数字
for i in n:
    sum = sum + int(i)
for j in str(sum):
    num = int(j)
    print(tran(num))

cloudguest的主页 cloudguest | 初学一级 | 园豆:194
提问于:2019-09-15 14:13
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册