python 转换数字为钱数
- 作者: 大瑶凌丸子
- 来源: 51数据库
- 2022-08-12
目标:
输入一串数字,将其输出为几元几角几分
程序:
#!/usr/bin/env python
#coding:utf8
num_dict = {'1':'一','2':'二','3':'三','4':'四','5':'五',
'6':'六','7':'七','8':'八','9':'九'}
money_dict = {'-2':'分','-1':'角','0':'元','1':'十',
'2':'百','3':'千','4':'万','8':'亿'}
def trans(money):
money_str = []
for index,value in enumerate(money[0][::-1]):
remain = index%4
if value != '0':
if remain != 0:
money_str.insert(0,num_dict[value]+money_dict[str(remain)])
else:
money_str.insert(0,num_dict[value]+money_dict[str(index)])
18 elif remain == 0 and (index+1) != len(money[0]):
19 money_str.insert(0,money_dict[str(index)])
20 if len(money) > 1:
21 for index,value in enumerate(money[1]):
22 if index > 1:
23 break
24 if value != 0:
25 money_str.append(num_dict[value]+money_dict['-'+str(index+1)])
26 print ''.join(money_str)
27
28 def main():
29 input_str = raw_input('Entry your money:')
30 money = input_str.split('.')
31 trans(money)
32
33 if __name__ == '__main__':
34 main()
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
