Python记账程序
2021/6/5 1:21:38
本文主要是介绍Python记账程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
基于 Python,实现记账,用于计算一段时间内每个人的收益。
class OurEth: @staticmethod def miner_power(num): cp = list(map(float, input('请输入第{}个矿工的各个矿机的算力:'.format(num)).split(' '))) miner_cp = sum(cp) return miner_cp def ratio_power(self, day): miner_num = int(input('请输入第{}天的矿工数量:'.format(day))) cp_list = [] for num in range(miner_num): miner_cp = self.miner_power(num + 1) cp_list.append(miner_cp) ratio_list = [] for cp in cp_list: ratio_list.append(cp / sum(cp_list)) return miner_num, ratio_list def eth_income(self): price = int(input('请输入以太币价格:')) eth_list = list(map(float, input('请输入每天的挖取的以太币数量:').split(' '))) wh_eth = [] zhb_eth = [] yzh_eth = [] zl_eth = [] other_eth = [] for day, eth in enumerate(eth_list): miner_num, ratio_list = self.ratio_power(day + 1) if miner_num > 0: wh_eth.append(eth * ratio_list[0]) if miner_num > 1: zhb_eth.append(eth * ratio_list[1]) if miner_num > 2: yzh_eth.append(eth * ratio_list[2]) if miner_num > 3: zl_eth.append(eth * ratio_list[3]) if miner_num > 4: other_eth.append(eth * ratio_list[4]) wh_eth = sum(wh_eth) zhb_eth = sum(zhb_eth) yzh_eth = sum(yzh_eth) zl_eth = sum(zl_eth) other_eth = sum(other_eth) wh_ic = wh_eth * price zhb_ic = zhb_eth * price yzh_ic = yzh_eth * price zl_ic = zl_eth * price other_ic = other_eth * price return print( 'wh_eth:{} wh_ic:{}\nzhb_eth:{} zhb_ic:{}\nyzh_eth:{} yzh_ic:{}\nzl_eth:{} zl_ic:{}\nother_eth:{} other_ic:{}\n' \ .format(wh_eth, wh_ic, zhb_eth, zhb_ic, yzh_eth, yzh_ic, zl_eth, zl_ic, other_eth, other_ic)) if __name__ == '__main__': eth0604 = OurEth() eth0604.eth_income()
这篇关于Python记账程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python