Use a variable like s (with fd s) to vary the speed of the car.

In the program above, it starts at s = 0, but holding the up-arrow changes it like this:

s = min(s + 0.1, 3)
Add 0.1 to s.
s = min(s + 0.1, 3)
Pick s + 0.1 or 3, whichever is smaler.
s = min(s + 0.1, 3)
Store the answer as the new value of s.
s = 0.0   ⇒   s = 0.1
s = 0.1   ⇒   s = 0.2
s = 0.2   ⇒   s = 0.3
...
s = 2.9   ⇒   s = 3.0
s = 3.0   ⇒   s = 3.0

Use else to do something when an if does not happen. When you let go of the up-arrow, the else runs s = max(s - 0.2, 0), which makes s go gradually down to zero to slow down the car.