CBSE Class 11 Computer Science
Question 80 of 98
Python Programming Fundamentals — Question 42
Back to all questionsThe error in the above code fragment occurs when trying to perform arithmetic operation on the result of the input() function. The input() function returns a string, even if the user enters a number. Therefore, attempting to subtract 1 from cl (which is a string) will raise a TypeError. The corrected code is:
cl = int(input("Enter your class: "))
print("Last year you were in class", cl - 1)