mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Michele Sessa
c4ea506acf
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
Numerical operation
Instructions
Create a file numerical_operations.py
containing the following functions:
add(a, b)
subtract(a, b)
multiply(a, b)
power(a, b)
square(a)
We assume that a
and b
are numbers (int
or float
).
Usage
Here is a possible test.py
to test your functions:
import numerical_operations
print(numerical_operations.add(2, 2))
print(numerical_operations.subtract(10, 5))
print(numerical_operations.multiply(3, 4))
print(numerical_operations.power(3, 3))
print(numerical_operations.square(3))
$ python test.py
4
5
12
27
9
$
[Optional] Use a virtual environnement to run python code locally
Virtual environments can help you to run your code locally.
Learn all you need about virtual environments.
Here, we setup a virtual environment with Miniconda.
First, download and install Miniconda.
Then, use those commands to create a new environment:
# create a new virtual environment for python 3.10
$ conda create --name my_env python=3.10
# activate your new environment
$ conda activate my_env
# From now, all python command use this python version in this terminal
$ python --version
Python 3.10.4
We advise you to create one virtual environment per python project. Later, we could also install external packages on our environment.
Hints
- You could
import math
at the start of your file to use the functions defined in that library (for examplemath.sqrt()
).