The description is rather long but you are given all needed formulas (almost:-)

John has bought a bike but before going moutain biking he wants us to do a few simulations.

He gathered information:

- His trip will consist of an ascent of `dTot` kilometers with an average slope of `slope` *percent* 
- We suppose that: there is no wind, John's mass is constant `MASS = 80 (kg)`, his power (generated at time `t` by pedaling and measured in watts)
at the start of the trip is `WATTS0 = 225 (watts)`
- We don't take account of the rolling resistance
- When he starts climbing at t = 0 his initial speed (pushed start) is `v0 (km/h)`
- His initial acceleration `gamma` is 0.
`gamma` is in `km/h/min` at time `t`. It is the number of kilometers per hour he gains or loses in the next *minute*. 
- Our time step is `DELTA_T = 1.0 / 60.0` (in minutes)

Furthermore (constants in uppercase are given below):

 - Because of tiredness, he *loses* D_WATTS * DELTA_T of power at each DELTA_T. 
 - calcul of acceleration:
  
  Acceleration has three components:
    - 1) on an ascent where the slope is `slope` the effect of earth gravity is given by:
    
    `- GRAVITY_ACC * function(slope)`
    
    (Beware: here the `slope`is a percentage, it is not an angle. You have to determine `function(slope)`).
    
    Some help for `function(slope)`:
    
    a) slope: 
    
    
    
    b) earth gravity:
  
    https://en.wikipedia.org/wiki/Gravity_of_Earth
    
    - 2) air drag is 
    
    `- DRAG * abs(v) * abs(v) / MASS` where `v` is his current speed
    
    - 3) if his power and his speed are both strictly positive we add the thrust (by pedaling) which is: 
    
    `+ G_THRUST * watts / (v * MASS)` where `watts` is his current power
    
    - 4) if his total `acceleration is <= 1e-5` we set acceleration to 0
 - If `v - 3.0 <= 1e-2` John gives up


```
Constants:
GRAVITY_ACC = 9.81 * 3.6 * 60.0                        // gravity acceleration
DRAG        = 60.0 * 0.3 / 3.6                         // force applied by air on the cyclist
DELTA_T     = 1.0 / 60.0                               // in minutes
G_THRUST    = 60 * 3.6 * 3.6                           // pedaling thrust
MASS        = 80.0                                     // biker's mass
WATTS0      = 225.0                                    // initial biker's power
D_WATTS     = 0.5                                      // loss of power
(Note: watts at time t + DELTA_T is watts at time t minus D_WATTS * DELTA_T)

Parameters:
double dTot                                            // distance to travel in km
double v0                                              // initial speed km/h
double slope                                           // ascent in percentage (don't forget to divide by 100 when needed)

Variables that can be used:
t                                                      // time
gamma                                                  // total acceleration with its 3 components
v                                                      // speed
d                                                      // distance travelled
watts                                                  // biker's power 

```
#### Task:
Write function
`temps(v0, slope, dTot)` which returns as a *rounded* integer the time `t` in minutes needed to travel `dTot`. 
If John gives up return `-1`.

As a reminder:

1) speed at (t + DELTA_T) = (speed at t) + gamma * DELTA_T

2) distance at (t + DELTA_T) can be taken as (distance at t) + speed * DELTA_T / 60.0 where speed is calculated with 1).

```
Examples:
temps(30, 5, 30) -> 114
temps(30, 20, 30) -> -1
temps(30, 8, 20) -> 110
```
Reference:

Difficulty: introductory

Starter code:

def temps(v0, slope, d_tot):
	

Solutions:
from math import sin, atan

def temps(v0, slope, d_tot):
    GRAVITY_ACC = 9.81 * 3.6 * 60.0                   # gravity acceleration
    DRAG = 60.0 * 0.3 / 3.6                           # force applied by air on the cyclist
    DELTA_T = 1.0/60.0                                # in minutes
    D_WATTS = 0.5                                     # power loss in Watts / minute
    G_THRUST = 60 * 3.6 * 3.6                         # acceleration due to biker's power
    MASS = 80                                         # biker's MASS
    WATTS0 = 225                                      # initial biker's power

    t = 0.0          # time in minutes
    d = 0.0          # distance traveled in km
    v = v0           # initial speed km/h
    gamma = 0.0      # acceleration in km/h/minute
    watts = WATTS0   # biker's power (watts at time t + DELTA_T is watts at time t - D_WATTS * DELTA_T)
    slopeGravityAcc = -GRAVITY_ACC * sin(atan(slope / 100.0))
    while (d <= d_tot):
        t += DELTA_T
        # new power
        watts -= D_WATTS * DELTA_T # tiredness
        # earth gravity due to slope and DRAG due to air resistance
        gamma = slopeGravityAcc - DRAG * abs(v) * abs(v) / MASS
        # acceleration due to biker's power
        if ((watts > 0.0) and (v > 0.0)):
            gamma += G_THRUST * watts / (v * MASS);
        # acceleration too small -> acc = 0
        if (abs(gamma) <= 1e-5):
            gamma = 0.0;
        else:
            v += gamma * DELTA_T
        # new distance
        d +=  v  * DELTA_T / 60.0 # v in km/h, DELTA_T in minutes
        # speed too slow, John stops
        if (v - 3.0 <= 1e-2):
            return -1
    return round(t)


from math import *

# Constants:
GRAVITY_ACC = 9.81 * 3.6 * 60.0                        # gravity acceleration
DRAG        = 60.0 * 0.3 / 3.6                         # force applied by air on the cyclist
DELTA_T     = 1.0 / 60.0                               # in minutes
G_THRUST    = 60 * 3.6 * 3.6                           # pedaling thrust
MASS        = 80.0                                     # biker's mass
WATTS0      = 225.0                                    # initial biker's power
D_WATTS     = 0.5   

def gamma(v, watts, slope):
    temp = -GRAVITY_ACC * sin(atan(0.01 * slope))
    temp = temp -  DRAG * abs(v) * abs(v)/ MASS 
    temp = temp +  G_THRUST * watts / (v * MASS)
    if abs(temp) <= 0.00001: temp = 0
    return temp


def temps(v0, slope, d_tot):
    d = 0
    t = 0
    v = v0
    watts = WATTS0

    while (d < d_tot):
        
        watts = watts - D_WATTS * DELTA_T
        v = v + gamma(v, watts, slope) * DELTA_T
        d = d + v * DELTA_T/60
        t = t  + DELTA_T
        if v - 3.0 <= 0.01: return -1
    
    return round(t)

from math import atan,sin
GRAVITY_ACC = 9.81 * 3.6 * 60.0
DRAG        = 60.0 * 0.3 / 3.6
DELTA_T     = 1.0 / 60.0
G_THRUST    = 60 * 3.6 * 3.6
MASS        = 80.0
WATTS0      = 225.0
D_WATTS     = 0.5

def temps(v0, slope, d_tot):
    t=0
    v=v0
    d=0
    watts=WATTS0
    theta=atan(slope/100)
    while(d<d_tot):
        t+=DELTA_T
        watts-=D_WATTS*DELTA_T
        gamma=G_THRUST*watts/(v*MASS)
        gamma-=GRAVITY_ACC*sin(theta)
        gamma-=DRAG*v*v/MASS
        v+=gamma*DELTA_T
        if v-3<=1e-2:
            return -1
        d+=v*DELTA_T/60
    return round(t)

import math


GRAVITY_ACC = 9.81 * 3.6 * 60.0  # gravity acceleration
DRAG = 60.0 * 0.3 / 3.6  # force applied by air on the cyclist
DELTA_T = 1.0 / 60.0  # in minutes
G_THRUST = 60 * 3.6 * 3.6  # pedaling thrust
MASS = 80.0  # biker's mass
WATTS0 = 225.0  # initial biker's power
D_WATTS = 0.5  # loss of power at each deltaT


def temps(v0, slope, d_tot):
    t = 0  # time
    gamma = 0  # total acceleration with its 3 components
    v = v0  # speed
    d = 0  # distance travelled
    watts = WATTS0  # biker's power

    # angle of inclination
    alpha = math.atan(slope / 100.0)

    while d < d_tot:
        if v - 3.0 <= 0.01:
            return -1
        t += DELTA_T
        watts -= D_WATTS * DELTA_T
        gamma = (-GRAVITY_ACC * math.sin(alpha)) + (-DRAG * abs(v) * abs(v) / MASS)
        if watts > 0 and v > 0:
            gamma += (G_THRUST * watts / (v * MASS))
        if abs(gamma) <= 0.00001:
            gamma = 0.0

        v += (gamma*DELTA_T)
        d += (v * DELTA_T / 60.0)

    return round(t)

import math
def temps(v0, slope, d_tot):
  
  GRAVITY_ACC = 9.81 * 3.6 * 60.0   # gravity acceleration
  DRAG        = 60.0 * 0.3 / 3.6    # force applied by air on the cyclist
  DELTA_T     = 1.0/60.0      # in minutes
  G_THRUST    = 60 * 3.6 * 3.6   # pedaling thrust
  MASS        = 80.0             #biker's mass
  WATTS0      = 225.0            # initial biker's power
  D_WATTS     = 0.5     
  
  t=0
   
  grav=-GRAVITY_ACC*math.sin(math.atan(slope/100))
  print(grav)
  
  v=v0
  watts=WATTS0
  s=0
  a=0
  while s<=d_tot:
    t+=DELTA_T
    watts-=D_WATTS*DELTA_T

    drag=DRAG*abs(v)*abs(v)/ MASS
    trst=(G_THRUST*watts)/(v*MASS)
    a=grav-drag+trst
   # print("G= ",grav,"Drag = ",drag," Trst= ",trst, "## A =", a)
    
    
    #print(a)
    if abs(a)<= 10**(-5):
      a=0
    
     
    v= v+a*DELTA_T
    if v-3.0 <= 0.01:
      return -1

    s=s+v*DELTA_T/60
    #print(v)
    #print("s= ",s,"v= ",v,"a= ",a)
  print(t,s)
 
  return round(t)

def temps(v0, slope, d_tot):
    GRAVITY_ACC = 9.81 * 3.6 * 60.0  
    DRAG        = 60.0 * 0.3 / 3.6   
    DELTA_T     = 1.0 / 60.0         
    G_THRUST    = 60 * 3.6 * 3.6     
    MASS        = 80.0               
    WATTS0      = 225.0              
    D_WATTS     = 0.5                
    
    t=0
    gamma=0
    v=v0
    d=0
    watts=WATTS0
    w=wei(slope,MASS)
    while d<d_tot:
        t+=DELTA_T
        watts = watts - D_WATTS*DELTA_T
        grav=GRAVITY_ACC*w
        drag=DRAG*v*v/MASS
        gamma=-grav-drag
        if watts>0<v:
            gamma+= G_THRUST * watts /(v*MASS)
        if abs(gamma)<=1e-5:gamma=0
        v=v+gamma*DELTA_T
        d=d+v*DELTA_T/60
        if v-3 <= 1e-2:return -1
    return round(t)
    
import math
def wei(slope,MASS):
    angle= math.atan(slope/100)
    return  math.sin(angle)

from math import *
#import numpy as np
#np.set_printoptions(precision=4)

GRAVITY_ACC = 9.81 * 3.6 * 60.0                        #// gravity acceleration
DRAG        = 60.0 * 0.3 / 3.6                         #// force applied by air on the cyclist
DELTA_T     = 1.0 / 60.0                               #// in minutes
G_THRUST    = 60 * 3.6 * 3.6                           #// pedaling thrust
MASS        = 80.0                                     #// biker's mass
WATTS0      = 225.0                                    #// initial biker's power
D_WATTS     = 0.5                                      #// loss of power at each deltaT

def temps(v0, slope, d_tot):
    t,d,v,watts = 0,0,v0,WATTS0    
    def nextAcc():
        a= - GRAVITY_ACC * slope/sqrt(10000+slope**2) - DRAG * abs(v) ** 2 / MASS + G_THRUST * watts / (v * MASS)
        return a if abs(a)>1e-5 else 0
    def nextVel():
        return v+gamma*DELTA_T
    def nextPow():
        return watts - D_WATTS * DELTA_T
    def nextDist():
        return d+v*DELTA_T/60+.5*gamma*(DELTA_T/60)**2  # distance travelled = v*t + .5*a*t**2
    def nextT():
        return t+DELTA_T    
    gamma=nextAcc()
    
    while(d_tot-d>0 and v - 3. > 1e-2):        
        t=nextT()
        v=nextVel()
        watts=nextPow()
        gamma=nextAcc()
        d=nextDist()
    return -1 if v -3. <1e-2 else int(round(t)) 


import math
def temps(v0, slope, d_tot):
    time = 0
    gamma = 0
    v = v0
    d = 0
    watts = 225.0
    while True:
        gamma = 0
        if d >= d_tot:
            return round(time)
        if (v - 3.0) <= 0.01:
            return -1
        watts -= (0.5 * (1.0 / 60.0))
        angle = math.atan(slope / 100)
        gamma -= 9.81 * 3.6 * 60.0 * math.sin(angle)
        gamma -= (60.0 * 0.3 / 3.6) * abs(v) * abs(v) / 80.0
        if watts > 0 and v > 0:
            gamma += 60 * 3.6 * 3.6 * watts / (v * 80.0)
        if abs(gamma) <= 0.00001:
            gamma = 0
        v += (gamma * (1.0 / 60.0))
        d += (v * (1.0 / 60.0) / 60.0)
        time += (1.0 / 60.0)

from math import atan, sin
def temps(v, slope, d_tot):
    answer = 0
    travelled = 0
    mass = 80
    power = 225
    power_loss = 0.5 / 60
    angle = atan(slope / 100)
    gravity_acc = 9.81 * 3.6 * 60
    gravityParallel = gravity_acc * sin(angle)
    drag = 60 * 0.3 / 3.6
    g_thrust = 60 * 3.6 * 3.6
    while travelled < d_tot:
        answer += 1
        airDrag = drag * v * v / mass
        thrust = 0
        if power > 0 and v > 0:
            thrust = g_thrust * power / v / mass
        gamma = - gravityParallel - airDrag + thrust
        if abs(gamma) <= 1e-5:
            gamma = 0
        v += gamma / 60
        if v - 3 <= 1e-2:
            return -1
        travelled += v / 60 / 60
        power -= power_loss
    return round(answer / 60)

import math

def temps(v0, slope, d_tot):
    GRAVITY_ACC = 9.81 * 60.0 * 3.6
    DRAG = 60.0 * 0.3 / 3.6  # air drag
    DELTA_T = 1.0 / 60.0
    G_THRUST = 60 * 3.6 * 3.6
    MASS = 80.0
    WATTS0 = 225.0
    D_WATTS = 0.5
    DELTA_P = D_WATTS * DELTA_T
    SLOPE = math.sin(math.atan(slope / 100.0))  # slope and slope(percentage)

    p = WATTS0               # cyclist power
    v = v0                   # actual speed
    a, d, t = 0.0, 0.0, 0.0  # acceleration, distance, time
    while d < d_tot:
        t += DELTA_T
        p -= DELTA_P
        a = -GRAVITY_ACC * SLOPE - DRAG * v ** 2 / MASS
        if v > 0 and p > 0:
            a += p * G_THRUST / v / MASS
        if abs(a) <= 1e-5:
            a = 0
        v += a * DELTA_T
        if v - 3.0 < 0.01:
            return -1
        d += v * DELTA_T / 60
    return int(round(t, 0))