7
Question Question 7
If a = (5, 4, 3, 2, 1, 0) evaluate the following expressions:
(a) a[0]
(b) a[1]
(c) a[a[0]]
(d) a[a[-1]]
(e) a[a[a[a[2]+1]]]
(a) 5
(b) 4
(c) 0
(d) 5
(e) 1
Explanation:
- The first index of tuple a is 5. Therefore, a[0] ⇒ 5
- The second index of tuple a is 4. Therefore,
a[1] ⇒ 4 a[0]represents first index of tuple a which is 5.
Now the expressiona[a[0]]has becomea[5]which implies 0.a[-1]represents last index of tuple a which is 0.
Now the expressiona[a[-1]]has becomea[0]which represents first element of a i.e. 5.a[2]represents third index of tuple a which is 3. Addition of 3 and 1 gives 4. Now the expressiona[a[a[a[2]+1]]]has becomea[a[a[4]]]where a[4] represents fifth index of tuple a i.e., 1.
Now the expressiona[a[a[4]]]has becomea[a[1]]wherea[1]represents second index of tuple a i.e., 4.
Now the expressiona[a[1]]has becomea[4]wherea[4]represents fifth index of a i.e. 1.