KnowledgeBoat Logo

Computer Science

Find the errors in following code fragment :


c = input( "Enter your class" )
print ("Last year you were in class") c - 1

Python Funda

46 Likes

Answer

There are two errors in this code fragment:

  1. c - 1 is outside the parenthesis of print function. It should be specified as one of the arguments of print function.
  2. c is a string as input function returns a string. With c - 1, we are trying to subtract a integer from a string which is an invalid operation in Python.

The corrected program is like this:


c = int(input( "Enter your class" )) 
print ("Last year you were in class", c - 1) 

Answered By

29 Likes


Related Questions