CBSE Class 10 Computer Applications
Question 2 of 31
Python Revision — Question 2
Back to all questions 2
Question Question 2
Anant has written following expressions in Python 2.7 :
a = - 4 % 1.5
b = - 4 // 1.5
c = 4.0 / 5
d = 4 / 5(a) Find out the values stored by a, b, c and d.
(b) What are the datatypes of a, b, c and d ?
(c) Why are the values of c and d not the same.
(a) The values stored in a, b, c, d are as follows:
| Variable | Value | Reason |
|---|---|---|
| a | -0.5 | Remainder of -4 divided by 1.5 is -0.5 |
| b | -3.0 | Floor division of -4 by 1.5 is -3.0 as floor division divides and truncates the fractional part from the result. |
| c | 0.8 | Division of 4.0 by 5 is 0.8, which is a floating-point value |
| d | 0 | Division of 4 by 5 is 0, and the fractional part is truncated |
(b) The data types of a, b, c and d are as follows:
| Variables | Datatypes |
|---|---|
| a | float |
| b | float |
| c | float |
| d | int |
(c) The values of 'c' and 'd' are not the same because of the difference in the division operation performed in each case:
'c' is the result of dividing two floating-point numbers, which preserves the decimal point and gives a floating-point result. 'd' is the result of dividing two integers, which truncates the fractional part and gives an integer result.