Page 196 - Computer Science V2.0 Class 11
P. 196
c. Assign a list containing strings 'Paper', 'Gel Pen', and 'Eraser' to a variable stationery.
stationary = ['Paper' , 'Gel Pen' , 'Eraser']
d. Assign the strings 'Mohandas', 'Karamchand', and 'Gandhi' to variables first, middle and last.
first = 'Mohandas'
middle= 'Karamchand'
last= 'Gandhi'
e. Assign the concatenated value of string variables first, middle and last to variable fullname. Make sure to incorporate blank spaces
appropriately between different parts of names.
fullname = first + ' ' + middle + ' ' + last
3. Write logical expressions corresponding to the following statements in Python and evaluate the expressions (assuming variables num1,
num2, num3, first, middle, last are already having meaningful values):
a The sum of 20 and –10 is less than 12.
b. num3 is not more than 24.
c. 6.75 is between the values of integers num1 and num2.
d. The string ‘middle’ is larger than the string ‘first’ and smaller than the string ‘last’.
e. List Stationary is empty.
Ans.
STATEMENT LOGICAL EXPRESSIONS
The sum of 20 and –10 is less than 12. (20 + (-10)) < 12
num3 is not more than 24. num3 <= 24 or not(num3 > 24)
6.75 is between the values of integers num1 and num2. (6.75 >= num1) and (6.75 <= num2)
The string 'middle' is larger than the string 'first' (middle > first) and (middle < last)
and smaller than the string 'last'.
List Stationary is empty. len(Stationary) == 0
4. Add a pair of parentheses to each expression so that it evaluates to True.
a. 0 == 1 == 2
b. 2 + 3 == 4 + 5 == 7
c. 1 < -1 == 3 > 4
Ans.
EXPRESSION EXPRESSION WITH PARENTHESIS
0 == 1 == 2 (0 == (1 == 2))
2 + 3 == 4 + 5 == 7 (2 + (3 == 4 ) + 5) == 7
1 < -1 == 3 > 4 (1 < -1 ) == (3 > 4)
5. Write the output of the following:
a. num1 = 4
num2 = num1 + 1
num1 = 2
print (num1, num2)
b. num1, num2 = 2, 6
num1, num2 = num2, num1 + 2
print (num1, num2)
c. num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print (num1, num2, num3)
Ans. a. num1 = 4
num2 = num1 + 1
num1 = 2
Output: 2,5
182 Touchpad Computer Science (Ver. 2.0)-XI

