# Class 11 Computer Science Chapter 5 Getting Started with Python NCERT Solution

### Chapter 5 – Getting Started with Python

#### 1. Which of the following identifier names are invalid and why?

(i) Serial_no. (ii) 1st_Room (iii) Hundred\$ (iv) Total Marks (v) Total_Marks (vi) total-Marks (vii) _Percentage (viii) True

Answer: – Valid Identifiers are :

(v) Total_Marks and (vii) _Percentage

Invalids Identifiers are :

(i) Serial_no. : Special Symbol . (dot) is not allowed in identifier name

(iii) Hundred\$ : Special Symbol \$ is not allowed in identifier name

(iv) Total Marks : Space is not allowed in identifier name

(vi) total-Marks : Special Symbol – (hyphen) is not allowed in identifier name

(viii) True : True is a keyword, and Keyword is not allowed in identifier name

#### 2. Write the corresponding Python assignment statements:

a) Assign 10 to variable length and 20 to variable breadth.

b) Assign the average of values of variables length and breadth to a variable sum.

c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.

Answer: stationery = [‘Paper’, ‘Gel Pen’, ‘Eraser’]

d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.

Answer: first , middle, last = ‘Mohandas’, ‘Karamchand’, ‘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.

Answer: 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.

Answer:- 20 + -10 < 12

b) num3 is not more than 24.

c) 6.75 is between the values of integers num1 and num2.

Answer:- (i) num1 < 6.75 < num2

(ii) num1 < 6.75 and 6.75 < num2

d) The string ‘middle’ is larger than the string ‘first’ and smaller than the string ‘last’.

Answer:- middle > first and middle < last

e) List Stationery is empty.

#### 4. Add a pair of parentheses to each expression so that it evaluates to True.

a) 0 == 1 == 2

Answer: – 0 == ( 1 == 2)
Reason:
0 == (1 == 2) => 0 == False => 0 == 0 => True
b) 2 + 3 == 4 + 5 == 7

Answer: (2 + (3 == 4)) + 5 == 7

Reason:
( 2 + (3 == 4) ) + 5 == 7
==> ( 2 + 0) + 5 == 7
==> 7 == 7 ==> True

c) 1 < -1 == 3 > 4

Answer: (1 < -1) == (3 > 4)

Reason :

(1 < – 1) == (3 > 4) ==> False == False ==> True

#### 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)```

Answer:- [Assume num1, num3 = 2, 3]

Output: 2 4 2

Note: NameError : undefined symbol num3 in line number 2

#### 6. Which data type will be used to represent the following data values and why?

a) Number of months in a year , b) Resident of Delhi or not, c) Mobile number, d) Pocket money, e) Volume of a sphere , f) Perimeter of a square, g) Name of the student, h) Address of the student

a) Number of months in a year: integer, number of month is a positive numeric value.

b) Resident of Delhi or not : Boolean, Resident of Delhi or not can be store as True or False

You can store it as String also, if you want to store value as “Yes” or “No”

c) Mobile number: String, because a mobile number not only contains number, it contain symbols like +, – and space also.

d) Pocket money: float, money can be stored as decimal number.

e) Volume of a sphere : float or integer, it is a numeric value. float is most appropriate.

f) Perimeter of a square: float, it is a numeric value.

g) Name of the student: String, Name can contain alphabet and space.

#### 7. Give the output of the following when num1 = 4, num2 = 3, num3 = 2

a) num1 += num2 + num3

print (num1)

[ Value of num1 = 4 + (3 + 2) = 9 ]

b) num1 = num1 ** (num2 + num3)

print (num1)

Note : [ num1 = 4 ** (3+2) = 4 ** 5 = 1024 ]

c) num1 *= num2 + c
Answer: NameError : Undefined symbol ‘c’

d) num1 = ‘5’ + ‘5’
print(num1)

Note : num1 = ’55’

e) print(4.00/(2.0+2.0))

f) num1 = 2 + 9 * (( 3 * 12) – 8)/10

print(num1)

Note : 2 + 9 * (36 – 8) / 10 = 2 + 9 * 28 / 10 = 2 + 25.2 = 27.2

g) num1 = 24 // 4 // 2

print(num1)

Note: num1 = 24 // 4 // 2 => (24//4)//2 => 6 // 2 => 3
h) num1 = float(10)

print (num1)

i) num1 = int(‘3.14’)

ValueError: invalid literal for int() with base 10: ‘3.14’ . It should be like num1 = int(float(‘3.14’))

print (num1)

Answer: 3.14 , if statement given in (m) is correct and executed properly.

k) print(10 != 9 and 20 >= 20)

l) print(10 + 6 * 2 ** 2 != 9//4 -3 and 29 >= 29/9)

m) print(5 % 10 + 10 < 50 and 29 <= 29)