Shared2017-2018 / Assignments / Solutions / Week 3.ipynbOpen in CoCalc
Author: Dominic Gowland
Views : 13
Description: Jupyter notebook 2017-2018/Assignments/Solutions/Week 3.ipynb
In [3]:
#Ex.6 #Make function def hi(name): print('Hello', name)
In [5]:
#Run function hi('Dom')
Hello Dom
In [1]:
#Ex.7.1 def egg(m, To, Ty): """ Calculates how long it takes to cook an egg. """ #import numpy import numpy as np #Ask for constants m=int(input('Mass of egg in grams: ')) M=m/1000 #To=int(input('Original temprature of egg: ')) Tw=100 #Ty=int(input('Desired yolk temprature:')) p=1.038*1000 c=3.7*1000 K=5.4*10**-1 #Calculate t #x=((M**(2/3))*c*p**(1/3))/((K*np.pi**2)*(4*np.pi)/3)**(2/3) #y=0.76*(To-Tw)/(Ty-Tw) #Z=np.log(y) T = M **(2/3) * c * p ** (1/3) \ / (K*np.pi ** 2 * (4 * np.pi/3) ** (2/3)) \ * np.log(0.76*(To-Tw)/(Ty-Tw)) t=(T)/60 #Print time print('The egg will take ', t, 'minutes to cook.') return(t)
In [2]:
# large egg hard boil fridge egg(67, 4, 70)
Mass of egg in grams:
The egg will take 1.859769056998862 minutes to cook.
1.859769056998862
In [10]:
# large egg hard boil room egg(67, 20, 70)
The egg will take 5.2536310631 minutes to cook.
5.2536310630987693
In [11]:
# small egg hard boil fridge egg(47, 4, 70)
The egg will take 5.2182424837 minutes to cook.
5.2182424837036061
In [12]:
# small egg hard boil room egg(47, 20, 70)
The egg will take 4.14770895797 minutes to cook.
4.1477089579741229
In [14]:
# large egg soft boil fridge egg(67, 4, 63)
The egg will take 5.04985749418 minutes to cook.
In [16]:
thsr=egg(47, 20, 70) thlr=egg(67, 20, 70) diffh = thlr-thsr print('The differance in cooking time for small and large hard boild eggs is', diff, 'minutes')
The egg will take 4.14770895797 minutes to cook. The egg will take 5.2536310631 minutes to cook. The differance in cooking time for small and large hard boild eggs is 0.777585377958 minutes
In [15]:
tssr=egg(47, 20, 63) tslr=egg(67, 20, 63) diffs=tslr-tssr print('The differance in cooking time for small and large soft boild eggs is', diff, 'minutes')
The egg will take 2.9162974705 minutes to cook. The egg will take 3.69388284846 minutes to cook. The differance in cooking time for small and large soft boild eggs is 0.777585377958 minutes
In [ ]: