From 7bace4bfe4cf6dcfd7bfe4974cea102421f00f02 Mon Sep 17 00:00:00 2001 From: Blaise Li <blaise.li__git@nsup.org> Date: Mon, 13 Jun 2022 15:59:40 +0200 Subject: [PATCH] Update exercise with divisions. --- source/Data_Types.rst | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/source/Data_Types.rst b/source/Data_Types.rst index c83d01c..e36ec6b 100644 --- a/source/Data_Types.rst +++ b/source/Data_Types.rst @@ -17,39 +17,28 @@ Assume that we execute the following assignment statements: :: width = 17 height = 12.0 - delimiter ='.' For each of the following expressions, write the value of the expression and the type (of the value of the expression) and explain. #. width / 2 - #. width / 2.0 + #. width // 2 #. height / 3 #. 1 + 2 * 5 - -Use the Python interpreter to check your answers. :: - >>> width = 17 - >>> 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 +Use the Python interpreter to check your answers. :: + >>> 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 -- GitLab