First function
Created on Dec. 15, 2016 by Julien Palard
Write a function computing the perimeter of a circle given its radius.
First read the function tutorial.
Your function should be named circle_perimeter(radius)
,
where the radius
parameter is the radius of a cirle.
Your function should return the perimeter of a circle of the given radius
.
To test it, we will import your function and try it with different values, such as:
1 2 3 4 5 6 |
|
Functions
For example, here is a simple function which takes a value and give it back unmodified:
1 2 |
|
We can call our identity
function and check it gave us back the given value:
1 2 |
|
So:
1 2 |
|
and:
1 2 |
|
are behaving the same. In the first case, we give 42
to print
,
which prints "42". In the 2nd example we give 42
to identity
,
which gives back 42
, which is directly given to print
, printing
"42" again.
We could also compare those equivalent codes:
1 2 |
|
1 2 |
|
1 2 3 |
|
Hints
- Do not print the result, you function should return it.
- You'll need to import the standard math module.
- More specifically you may use math.pi (or math.tau).