diff --git a/source/Data_Types.rst b/source/Data_Types.rst index c83d01ccf448f9fc319dc016cfabdcb514c8db91..e36ec6bbd1b5ed003a0a16c4726ad95b35be5215 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