# What do I add to my code to return a specific value?

How do I return the time value (t) at the time the kettle boils at 100 Celsius (T)

"""Code for a change in temperature of water in a kettle (A first order differential)

It is related by the equation:

dT/dt = p/(mc) -r(T-Ts)

Where T = temperature

p = Power supplied (2kW)

m = mass of substance (1kg)

c = heat capacity of the substance (4186J/kg/k)

r = cooling constant (0.07 celcius/minute)

Ts = temperature of the surroundings (20 celcius)

T is initially surrounding temperature

It is a decay equation so we can use the Euler Method

1) Produce graph of T vs t

2) Find time to boil

"""

import numpy as np

import matplotlib.pyplot as plt

#define your variables used in the kettle boiling equation from *Line 4*

p = 2000.0

m = 1

c = 4186

r = 0.07/60 #cooling constant converted to /second from /minute

Ts = 293

T1 = 293

t = 0

tEnd = 10000 #the max time in seconds

dt = 1 #step size of the graph in seconds

tdata = []

Tdata = []

Tana = []

for t in np.arange(t, tEnd, dt):

#Euler formula, T1 = T2 + mdt

T2 = T1 +( p /(m*c) -r*(T1-Ts)) * dt #this is updating new temperature value T1 by increasing initial T1 by

tdata.append(t) # adding the increasing temperature due to heating equation

Tdata.append(T1) #append means new value added to Tdata matrix

plt.plot(tdata,Tdata)

plt.xlabel('Time(s)')

plt.ylabel('Temperature (K)')

Be the first to answer this question.