Chapter 5 Solutions to all excercises
Excercise - 1
1 (i) A dot cannot be in a variable name
1 (iii) There is a special sign of dollar
1 (iv) There cannot be a space character in a variable name
1 (vi) '-' cannot be in a variable name
1 (viii) 'True' is a reserved word in Python so it cannot be usd as a variable name
In [3]:
# Excercise - 2
# Excercise 2(a)
length = 10
breadth = 20
# Excercise 2(b)
sum = (length + breadth) / 2
# Excercise 2(c)
stationary = ['Paper' , 'Gel Pen' , 'Eraser']
# Excercise 2(d)
first = "Mohandas"
middle = "Karamchand"
last = "Gandhi"
# Excercise 2(e)
full_name = first + " " + middle + " " + last
print(full_name)
Mohandas Karamchand Gandhi
Excercise - 3
(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 intege
Stationery is empty.
Answers
(a) 20 + (-10) < 12 (b) num3 <= 24 (c) (6.75 > num1) and (6.75 < num2) (d) (middle > first) and (middle < last) (e)
Excercise - 4
Q. Add a pair of parentheses to each expression so that it evaluates to True. (a) 0 == 1 == 2 (b) 2 + 3 == 4 + 5 ==
Answer:-
(a) 0 == (1 == 2) (b) (2 + (3 == 4) + 5) == 7 (c) (1 < -1) == (3 > 4)
Excercise - 1
1 (i) A dot cannot be in a variable name
1 (iii) There is a special sign of dollar
1 (iv) There cannot be a space character in a variable name
1 (vi) '-' cannot be in a variable name
1 (viii) 'True' is a reserved word in Python so it cannot be usd as a variable name
In [3]:
# Excercise - 2
# Excercise 2(a)
length = 10
breadth = 20
# Excercise 2(b)
sum = (length + breadth) / 2
# Excercise 2(c)
stationary = ['Paper' , 'Gel Pen' , 'Eraser']
# Excercise 2(d)
first = "Mohandas"
middle = "Karamchand"
last = "Gandhi"
# Excercise 2(e)
full_name = first + " " + middle + " " + last
print(full_name)
Mohandas Karamchand Gandhi
Excercise - 3
(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 intege
Stationery is empty.
Answers
(a) 20 + (-10) < 12 (b) num3 <= 24 (c) (6.75 > num1) and (6.75 < num2) (d) (middle > first) and (middle < last) (e)
Excercise - 4
Q. Add a pair of parentheses to each expression so that it evaluates to True. (a) 0 == 1 == 2 (b) 2 + 3 == 4 + 5 ==
Answer:-
(a) 0 == (1 == 2) (b) (2 + (3 == 4) + 5) == 7 (c) (1 < -1) == (3 > 4)