仅供参考

人民币转换

http://www.nowcoder.com/questionTerminal/00ffd656b9604d1998e966d555005a4b

while True:
    try:
        shuzhi = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
        jinwei = ['','拾','佰','仟']
        jinwei1 = ['','万','亿']
        s = input()
        integer,digit = s.split('.')
        integer_ = []
        for i,e in enumerate(integer[::-1]):
            if i%4 == 0 and e == '0':
                e = ''
            else:
                e = shuzhi[int(e)] + jinwei[i%4]
            if i % 4 == 0 and i != 0:
                e = e + jinwei1[i//4]
            integer_.append(e)
        integer = ''.join(integer_[::-1])

        if digit =='00':
            digit_ = '整'
        else:
            digit_1 = ''
            digit_2 = ''
            if digit[0] !='0':
                digit_1 = shuzhi[int(digit[0])] + '角'
            if digit[1] !='0':
                digit_2 = shuzhi[int(digit[1])] + '分'
            digit_ = digit_1+digit_2

        if integer[:2] =='壹拾':
            integer = integer.replace('壹拾', '拾')

        if integer!='':
            print('人民币'+integer+'元'+digit_)
        else:
            print('人民币'+digit_)


    except:
        break
全部评论

相关推荐

10-15 09:13
已编辑
天津大学 soc前端设计
点赞 评论 收藏
分享
点赞 2 评论
分享
牛客网
牛客企业服务