Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class hcm (object):
- def __init__ (self, nca,nha,nff):
- '''the number of carbon and hydrogen elements must be an integer while the name must be a string'''
- self.__nca = nca
- self.__nha = nha
- self.__nff = []
- self.__nff.append (nff)
- def __cmp__ (self,other):
- if self.__nca == other.__nca and self.__nha == other.__nha:
- return 0
- else:
- return 1
- def getnca (self):
- '''returns number of carbon atoms'''
- return self.__nca
- def getnha (self):
- '''returns number of hydrogen atoms'''
- return self.__nha
- def getnff (self):
- '''returns name'''
- return self.__nff
- def __str__ (self):
- '''returns a string with the molecule info'''
- string = ""
- for n in self.__nff:
- string += n
- mstring = string + " " + "C"+ str(self.__nca) + "H" + str(self.__nha)
- return mstring
- def modmol (self,other):
- self.__nff.append (other.__nff)
- def test ():
- molly = hcm(3,4,"molly")
- bigmolly = hcm(6,8,"bmolly")
- print molly
- print bigmolly
- # End of Part 1-------------------------------------------------------------
- mollylist = [] # list for all to use
- def addtolist (lomo):
- mollylist.append (lomo[0])
- for n in range(len(lomo)):
- for m in mollylist:
- if n > 0:
- if lomo[n] != m:
- mollylist.append(lomo[n])
- print mollylist #for debugging
- raw_input ("debug") #for debugging
- elif lomo[n] == m:
- m.modmol (lomo[n])
- print mollylist
- # End of part 2 -------------------------------------------------------------
- nof = "atoms.txt"
- def readarl (fo):
- line = fo.readline()
- return line
- def manline (line):
- split = line.split ()
- nameofa = split[0]
- stripped = split[1].strip("C")
- nums = stripped.split("H")
- carb = int(nums[0])
- harb = int(nums[1])
- return carb,harb,nameofa
- def makearo (carb,harb,name):
- mol = hcm(carb,harb,name)
- return mol
- def rar (nof):
- listofobj = []
- line = readarl (nof)
- while line !="":
- carb,harb,nameofa = manline (line)
- mobj = hcm(carb,harb,nameofa)
- listofobj.append(mobj)
- line = readarl (nof)
- return listofobj
- def aamtl ():
- fo = open(nof,"r")
- lomo = rar (fo)
- addtolist (lomo)
- #End of part 3-------------------------------------------------
- def test4():
- h=hcm(3,5,"test")
- b=hcm(3,4,"kest")
- print h==b
Add Comment
Please, Sign In to add comment