""" Ex 3.23 from "A Primer on..." Wrap the formula from ex 1.12 in a function. """ from math import log, pi def egg(M, To = 20, Ty = 70): rho = 1.038 c = 3.7 K = 5.4e-3 Tw = 100 t = (M**(2/3)*c*rho**(1/3))/(K*pi**2*(4*pi/3)**(2/3)) \ * log(0.76*(To-Tw)/(Ty-Tw)) return t """ The question text asks for a lot of combinations. This is easiest with lists and a nested for-loop.""" # small and large egg: mass = [47,67] #starting temp. from fridge and hot room: t_start = [4, 25] #target yoke temperature for soft and hard boiled t_yoke = [63, 70] #nested for-loop to run all combinations: for M in mass: for To in t_start: for Ty in t_yoke: t = egg(M = M, To = To, Ty = Ty) print(f"An egg with mass {M} and start temperature {To} takes {t/60:.1f} minutes to reach {Ty} degrees.") """ Terminal> python egg_func.py An egg with mass 47 and start temperature 4 takes 4.0 minutes to reach 63 degrees. An egg with mass 47 and start temperature 4 takes 5.2 minutes to reach 70 degrees. An egg with mass 47 and start temperature 25 takes 2.5 minutes to reach 63 degrees. An egg with mass 47 and start temperature 25 takes 3.8 minutes to reach 70 degrees. An egg with mass 67 and start temperature 4 takes 5.0 minutes to reach 63 degrees. An egg with mass 67 and start temperature 4 takes 6.6 minutes to reach 70 degrees. An egg with mass 67 and start temperature 25 takes 3.2 minutes to reach 63 degrees. An egg with mass 67 and start temperature 25 takes 4.8 minutes to reach 70 degrees. """