""" Exercise 3.23 from "A primer on..." Wrap the egg formula from earlier in a function, with M, To and Ty as arguments and the rest of the parameters defined as local variables inside the function. """ import numpy as np def egg(M, To=20, Ty=70): rho = 1.038 c = 3.7 K = 5.4e-3 Tw = 100 a = (M ** (2 / 3) * c * rho ** (1 / 3)) / (K * np.pi**2 * (4 * np.pi / 3) ** (2 / 3)) b = np.log(0.76 * (To - Tw) / (Ty - Tw)) t = a * b return t #Loop through all the options listed in the exercise: for Ty in 63, 70: for M in 47, 67: for To in 4, 25: t = egg(M=M, To=To, Ty=Ty) minutes = int(t / 60) seconds = int(t % 60) print(f"An egg with mass {M} and start temp {To} reaches {Ty} degrees after {minutes} minutes and {seconds} seconds") """ Terminal> python egg_func.py An egg with mass 47 and start temp 4 reaches 63 degrees after 3 minutes and 59 seconds An egg with mass 47 and start temp 25 reaches 63 degrees after 2 minutes and 32 seconds An egg with mass 67 and start temp 4 reaches 63 degrees after 5 minutes and 2 seconds An egg with mass 67 and start temp 25 reaches 63 degrees after 3 minutes and 12 seconds An egg with mass 47 and start temp 4 reaches 70 degrees after 5 minutes and 13 seconds An egg with mass 47 and start temp 25 reaches 70 degrees after 3 minutes and 46 seconds An egg with mass 67 and start temp 4 reaches 70 degrees after 6 minutes and 36 seconds An egg with mass 67 and start temp 25 reaches 70 degrees after 4 minutes and 46 seconds """