#This is the sixth lesson, based on Chemisty! # Ratio for PN:bakingSoda:sugar is 3:2:1 def smokeFlareRatio(PN,bakingSoda,sugar): sum = PN + bakingSoda + sugar if PN is sum/2: if bakingSoda is sum/3: if sugar is sum/6: #print "This is a valid combination, that satisfies the ratio 3:2:1" return True #print "This is an invalid combination!" return False print "Let's test the ratio checker itself" smokeFlareRatio(6,4,2) # This is a valid combination because is 3:2:1 is followed. print "The next one should fail!" smokeFlareRatio(6,5,2) # This is not a valid combination because 3:2:1 is not followed #Now they can write loops which goes through different combinations of # the ingredients and if the sum of the units is 40 and it is in the # ratio, then Perez can use the said units of each ingredients to make # the perfect amount of smoke to overcome the evil dentist #You probably should say he has three beakers for each ingredient, #and he can fill them up from a range of 1 to 50 def findIdealValues(target): maxRange = 50 #Go from 1 - 50 for each ingredient for PN in range(1,maxRange): for bakingSoda in range(1,maxRange): for sugar in range(1,maxRange): if smokeFlareRatio(PN, bakingSoda,sugar) is True: PN + bakingSoda + sugar if (PN + bakingSoda + sugar) == target: print "Use " , PN , bakingSoda , sugar ,"!" print "Perez can escape now! Woohoo!" findIdealValues(48)