CBSE Class 11 Computer Science Question 76 of 106

Python Fundamentals — Question 5

Back to all questions
5
Question

Question 5

What is the problem with the following code fragments ?

(i)

a = 3
    print(a)
b = 4
    print(b)
s = a + b
    print(s)
Answer

The problem with the above code is inconsistent indentation. The statements print(a), print(b), print(s) are indented but they are not inside a suite. In Python, we cannot indent a statement unless it is inside a suite and we can indent only as much is required.

(ii)

name = "Prejith"
age = 26
print ("Your name & age are ", name + age)

In the print statement we are trying to add name which is a string to age which is an integer. This is an invalid operation in Python.

(iii)

a = 3
s = a + 10
a = "New"
q = a / 10

The statement a = "New" converts a to string type from numeric type due to dynamic typing. The statement q = a / 10 is trying to divide a string with a number which is an invalid operation in Python.