CBSE Class 11 Computer Science
Question 124 of 173
Data Handling — Question 13
Back to all questions 13
Question Question 9
Consider the following code segment:
a = input()
b = int(input())
c = a + b
print(c)When the program is run, the user first enters 10 and then 5, it gives an error. Find the error, its reason and correct it
Answer
The error is:
TypeError: can only concatenate str (not "int") to str
It occurs because a is of type string but b is of type int. We are trying to add together a string operand and an int operand using addition operator. This is not allowed in Python hence this error occurs.
To correct it, we need to cast a to int like this:
a = int(input())