forked from CodeMouse92/DeadSimplePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.py
More file actions
29 lines (23 loc) · 715 Bytes
/
element.py
File metadata and controls
29 lines (23 loc) · 715 Bytes
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
class Element:
__slots__ = (
'name',
'number',
'symbol',
'family',
'iupac_num',
'__dict__',
'__weakref__'
)
def __init__(self, symbol, number, name, family, numeration):
self.symbol = symbol.title()
self.number = number
self.name = name.lower()
self.family = family.lower()
self.iupac_num = numeration
def __str__(self):
return f"{self.symbol} ({self.name}): {self.number}"
oxygen = Element('O', 8, 'oxygen', 'non-metals', 16)
iron = Element('Fe', 26, 'iron', 'transition metal', 8)
print(oxygen) # prints 'O (Oxygen): 8'
print(iron) # prints 'Fe (Iron): 26'
iron.atomic_mass = 55.845