Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python_one_week_4_biologists_solutions
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub-courses
python_one_week_4_biologists_solutions
Commits
7bace4bf
Commit
7bace4bf
authored
3 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Update exercise with divisions.
parent
960814c9
No related branches found
No related tags found
No related merge requests found
Pipeline
#83342
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/Data_Types.rst
+13
-24
13 additions, 24 deletions
source/Data_Types.rst
with
13 additions
and
24 deletions
source/Data_Types.rst
+
13
−
24
View file @
7bace4bf
...
@@ -17,39 +17,28 @@ Assume that we execute the following assignment statements: ::
...
@@ -17,39 +17,28 @@ Assume that we execute the following assignment statements: ::
width = 17
width = 17
height = 12.0
height = 12.0
delimiter ='.'
For each of the following expressions, write the value of the expression and the type (of the value of
For each of the following expressions, write the value of the expression and the type (of the value of
the expression) and explain.
the expression) and explain.
#. width / 2
#. width / 2
#. width / 2
.0
#. width /
/
2
#. height / 3
#. height / 3
#. 1 + 2 * 5
#. 1 + 2 * 5
Use the Python interpreter to check your answers. ::
>>> width = 17
Use the Python interpreter to check your answers. ::
>>> height = 12.0
>>> delimiter ='.'
>>>
>>> width / 2
8
>>> # both operands are integer so python done an euclidian division and threw out the remainder
>>> width / 2.0
8.5
>>> height / 3
4.0
>>> # one of the operand is a float (2.0 or height) then python pyhton perform a float division but keep in mind that float numbers are approximation.
>>> # if you need precision you need to use Decimal. But operations on Decimal are slow and float offer quite enough precision
>>> # so we use decimal only if wee need great precision
>>> # Euclidian division
>>> 2 // 3
0
>>> # float division
>>> 2 / 3
0.6666666666666666
>>> width = 17
>>> height = 12.0
>>> width / 2
8.5
>>> width // 2
8
>>> # // is to perform an euclidean division
>>> height / 3
4.0
>>> 1 + 2 * 5
11
Exercise
Exercise
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment