2021-03-19 Python 化学药品浓度质量计算器

Python工具代码 专栏收录该内容
11 篇文章 1 订阅
#!/usr/bin/python
# -*- coding: UTF-8 -*-


class Chemical:

    empCount = 0

    def __init__(self, chemical_name, molecule_weight, bulk_state, density):
        self.chemical_name = chemical_name
        self.molecule_weight = molecule_weight
        self.bulk_state = bulk_state
        self.density = density


KOH = Chemical("KOH", 56.11, 'p', "")
NaOH = Chemical("NaOH", 39.996, 'p', "")
NaCA = Chemical("NaCA", 258.07, 'p', "")
AA = Chemical("AA", 176.12, 'p', "")
H2SO4 = Chemical("H2SO4", 98, 'l', 1.831)
C2H5OH = Chemical("C2H5OH", 46.07, 'l', 0.8)
CH3OH = Chemical("CH3OH", 32.04, 'l', 0.79)
molecules = [KOH, NaOH, NaCA, AA, H2SO4, C2H5OH, CH3OH]
print('Chemical name list:\n [1] KOH \n [2] NaOH \n [3] NaCA \n [4] AA \n [5] H2SO4 \n [6] C2H5OH \n [7] CH3OH \n')
start = 1
while start:
    num = input("请输入药品序号:")
    num = int(num) - 1
    concentration = input("请输入浓度/M:")
    concentration = float(concentration)
    bulk = input("请输入体积/ml:")
    bulk = float(bulk)
    if molecules[num].bulk_state == 'p':
        mass_mg = concentration*molecules[num].molecule_weight*bulk
        print('Using', molecules[num].chemical_name, " ", mass_mg, "mg\n")
    elif molecules[num].bulk_state == 'l':
        bulk_ml = 0.001*concentration * molecules[num].molecule_weight * bulk/molecules[num].density
        print('Using ', molecules[num].chemical_name, " ", str(bulk_ml), " ml\n")


 

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值