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:
c - 1
is outside the parenthesis of print function. It should be specified as one of the arguments of print function.- 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
Find the errors in following code fragment : (The input entered is XI)
c = int (input ( "Enter your class") ) print ("Your class is", c)
Consider the following code :
name = input ("What is your name?") print ('Hi', name, ',') print ("How are you doing?")
was intended to print output as
Hi
, How are you doing ? But it is printing the output as:
Hi
, How are you doing? What could be the problem ? Can you suggest the solution for the same ?
What will be returned by Python as result of following statements?
(a) >>> type(0)
(b) >>> type(int(0))
(c) >>>.type(int('0')
(d) >>> type('0')
(e) >>> type(1.0)
(f) >>> type(int(1.0))
(g) >>>type(float(0))
(h) >>> type(float(1.0))
(i) >>> type( 3/2)
What will be the output produced by following code ?
>>> str(print())+"One"