#!/usr/bin/python # TYPE:sciencemath # DESC:A program that finds the volume and density of an object, based on the mass in air, the mass in a liquid, and the density of that liquid. class Solid: def __init__(self): self.mass=input("Mass in air? ") self.massLiquid=input("Mass in liquid? ") self.massLost = self.mass-self.massLiquid def getVol(self,liquid): self.volume = liquid.volume def calcDense(self): self.density = self.mass/self.volume def showStuff(self): print "The piece of metal weighs",str(self.mass)+"g, has a volume of",str(self.volume)+"ml, and a density of",str(self.density)+"g/ml!" class Liquid: def __init__(self, mass): self.density=input("Density of liquid? ") self.mass=mass self.volume=self.mass/self.density metal = Solid() oil = Liquid(metal.massLost) metal.getVol(oil) metal.calcDense() metal.showStuff()