Fo each class defined, you can provide a constructor that initializes attributes of a new object. Python, the constructor is always named _._ in it _.. (with two underscores before and after nit). The constructor is called automatically when you create a new object. dd the following constructor to the top of your Atom class. By convention, the constructor is /pically the first method in a class definition. Also edit the "_ _-main_ _" block of code as shown.
class Atom:
""*'An element from the periodic table. =n"""
def _.init__(self, symbol, atomic, zass, isotope=12):
"""Constructs an Atom with the given values. """
self. symbol = a symbol
self, atomic = atomic
self.mass = mass
self. isotope = isotope
... previous methods from Model 1 ...
if …n name …=n−main … :
oxygen = Atom (0′,8,15.999,16)
carbon =A tom (′C,1,6,12.001)
oxygen. neutrons()
carbon. neutrons ()
oxygen,grams_to_moles(24)
carbon. grams_to_moles(24)
in a python shell, try to create a new atom object called hydrogen with only two arguments. write your statement in the space below. what is the reason for the error you see?

Q&A Education