This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calculate of MolarMass.py
58 lines (53 loc) · 4.35 KB
/
Calculate of MolarMass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 11 18:33:28 2019
版权所有(c)<2019> 氘化氢
反996许可证版本1.0
在符合下列条件的情况下,特此免费向任何得到本授权作品的副本(包括源代码、文件和/或相关内容,以下
统称为“授权作品”)的个人和法人实体授权:被授权个人或法人实体有权以任何目的处置授权作品,包括但
不限于使用、复制,修改,衍生利用、散布,发布和再许可:
1. 个人或法人实体必须在许可作品的每个再散布或衍生副本上包含以上版权声明和本许可证,不得自行修
改。
2. 个人或法人实体必须严格遵守与个人实际所在地或个人出生地或归化地、或法人实体注册地或经营地
(以较严格者为准)的司法管辖区所有适用的与劳动和就业相关法律、法规、规则和标准。如果该司法管辖
区没有此类法律、法规、规章和标准或其法律、法规、规章和标准不可执行,则个人或法人实体必须遵守国
际劳工标准的核心公约。
3. 个人或法人不得以任何方式诱导或强迫其全职或兼职员工或其独立承包人以口头或书面形式同意直接或
间接限制、削弱或放弃其所拥有的,受相关与劳动和就业有关的法律、法规、规则和标准保护的权利或补救
措施,无论该等书面或口头协议是否被该司法管辖区的法律所承认,该等个人或法人实体也不得以任何方法
限制其雇员或独立承包人向版权持有人或监督许可证合规情况的有关当局报告或投诉上述违反许可证的行为
的权利。
该授权作品是"按原样"提供,不做任何明示或暗示的保证,包括但不限于对适销性、特定用途适用性和非侵
权性的保证。在任何情况下,无论是在合同诉讼、侵权诉讼或其他诉讼中,版权持有人均不承担因本软件或
本软件的使用或其他交易而产生、引起或与之相关的任何索赔、损害或其他责任。
"""
import re
elements = {"H": 1.008, "He": 4.003, "Li": 6.941, "Be": 9.012, "B": 10.81, "C": 12.011, "N": 14.007, "O": 15.999, "F": 18.998, "Ne": 20.179, "Na": 22.990, "Mg": 24.305, "Al": 26.982, "Si": 28.086, "P": 30.974, "S": 32.06, "Cl": 35.453, "Ar": 39.948, "K": 39.098, "Ca": 40.08, "Sc": 44.956, "Ti": 47.88, "V": 50.942, "Cr": 51.996, "Mn": 54.938, "Fe": 55.847, "Co": 58.933, "Ni": 58.693, "Cu": 63.546, "Zn": 65.39, "Ga": 69.72, "Ge": 72.61, "As": 74.922, "Se": 78.96, "Br": 79.904, "Kr": 83.80, "Rb": 85.468, "Sr": 87.62, "Y": 88.906, "Zr": 91.224, "Nb": 92.906, "Mo": 95.94, "Tc": 97.907, "Ru": 101.07, "Rh": 102.906, "Pd": 106.42, "Ag": 107.868, "Cd": 112.411, "In": 114.82, "Sn": 118.710, "Sb": 121.757, "Te": 127.60, "I": 126.905, "Xe": 131.29, "Cs": 132.905, "Ba": 137.327, "La": 138.905, "Ce": 140.12, "Pr": 140.908, "Nd": 144.24, "Pm": 144.913, "Sm": 150.36, "Eu": 151.96, "Gd": 157.25, "Tb": 158.925, "Dy": 162.50, "Ho": 164.930, "Er": 167.26, "Tm": 168.934, "Yb": 173.04, "Lu": 174.967, "Hf": 178.49, "Ta": 180.948, "W": 183.85, "Re": 186.207, "Os": 190.2, "Ir": 192.22, "Pt": 195.08, "Au": 196.967, "Hg": 200.59, "TI": 204.383, "Pb": 207.2, "Bi": 208.980, "Po": 208.982, "At": 209.987, "Rn": 222.018, "Fr": 223.020, "Ra": 226.025, "Ac": 227.028, "Th": 232.038, "Pa": 231.036, "U": 238.029, "Np": 237.048, "Pu": 244.064, "Am": 243.061, "Cm": 247.070, "Bk": 247.070, "Cf": 251.080, "Es": 252.083, "Fm": 257.095, "Md": 258.099, "No": 259.101, "Lr": 262, "Rf": 261, "Db": 262, "Sg": 263, "Bh": 262, "Hs": 265, "Mt": 266}
def cut(compoundstr):
pattern="[A-Z]"
cut0=re.sub(pattern,lambda x:" "+x.group(0),compoundstr)
cut1=cut0.split()
return cut1
def calc(eles):
if eles[-1] in "0123456789":
return elements[eles[:-1]]*int(eles[-1])
else:
return elements[eles]
def calu():
s=0
compound=input("input the compound to calculate the molarmass:\n")
print("start cutting")
elementslist=cut(compound)
print(elementslist)
for i in elementslist:
print(i)
print(calc(i))
s+=calc(i)
return s
if __name__ =="__main__":
while input("input enter to contiune,other to exit")=="":
try:
print("calculate finished.\n",calu())
except KeyError:
print("input error!")
break