Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def atoms(self, symbol):
  2.         """Return the number of type 'symbol' atoms in the molecule        
  3.        
  4.           Raises:
  5.              KeyError - if the symbol is not in atomic periodic table
  6.  
  7.        """
  8.         molTest = Molecule(symbol)
  9.         molTest.check_symbols()
  10.        
  11.         total_symbols = 0
  12.         total_symbols_loop = 0
  13.         molecule_list = self._tokentree()
  14.         for item in molecule_list:
  15.             if len(item[0]) > 1:
  16.                 for x in item[0]:
  17.                     if x[0] == symbol:
  18.                         total_symbols_loop = 0
  19.                         total_symbols_loop = total_symbols_loop + x[1]
  20.                 total_symbols = total_symbols_loop * item[1]
  21.             else:
  22.                 if item[0] == symbol:
  23.                     total_symbols = total_symbols + item[1]
  24.         return total_symbols
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement