-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion_1_answer.txt
37 lines (21 loc) · 1.42 KB
/
question_1_answer.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
QUESTION 1
1. Comment about the possible output values of the following code in Python and how you would
overcome the drawbacks when using different Python versions
As suggested by the question, the main issue with these lines of code is that different Python versions will interpret
the '/' operator differently.
Python 2.x will interpret the '/' operator as an integer division if the inputs are integers.
Python 3.x will interpret the '/' operator as a floating point division.
That said, the result variable will be equal to 1 for Python 2.x interpreters and will be 1.4 for
Python 3.x interpreters.
I believe that the best way to handle potentials exceptions that this difference could cause is to directly deploy
all the Python source code in a Python Virtual environment.
This test will be delivered as a project in a virtual environment, and all that's needed is to run in the root folder of
this project:
$ source .venv/bin/activate
And the virtual environment will be activated. This will isolate the execution environment not only to a specific Python version
but also ensure only the needed dependencies will be used.
If you are using Windows (non-UNIX), you might want to create a new Virtual Environment as they are not cross-OS compatible.
In that case, please delete the .venv directory and create a new environment using python 3.x.
> python -m venv .venv
And then activate that environment.
.venv\Scripts\activate