Put the lesson Representing Materials Data into practice by writing a program yourself.
For a light, stiff component you need a high specific stiffness: Young's modulus divided by density.
The starter code holds four candidate materials as a list of dictionaries. Report each one's specific stiffness and pick the best.
specific_stiffness(material) that takes one record and returns its modulus divided by its density.Aluminium 6061: 25.6 (1 decimal place).max() with key= to find the best material and print Best: ....Aluminium 6061: 25.6 Alumina: 96.2 Steel AISI 4140: 26.1 Nylon 6: 2.4 Best: Alumina
Write your program below and press Run. Each run is checked against the expected output.
Press Run to see what your program prints.
One possible solution. Other programs that print the same output are correct too.
materials = [ {"name": "Aluminium 6061", "density": 2.70, "youngs_modulus": 69}, {"name": "Alumina", "density": 3.95, "youngs_modulus": 380}, {"name": "Steel AISI 4140", "density": 7.85, "youngs_modulus": 205}, {"name": "Nylon 6", "density": 1.14, "youngs_modulus": 2.7},] # density in g/cm³, modulus in GPadef specific_stiffness(material): """Young's modulus divided by density, in GPa per (g/cm³).""" return material["youngs_modulus"] / material["density"]for material in materials: print(f"{material['name']}: {specific_stiffness(material):.1f}")best = max(materials, key=specific_stiffness)print("Best:", best["name"])