CBSE Class 12 Computer Science Question 12 of 103

Working with Functions — Question 4

Back to all questions
4
Question

Question 4

Find the errors in following function definitions :

  1.  def main()  
         print ("hello")
  2. def func2():  
         print(2 + 3)
  3. def compute():   
         print (x * x)
  4. square (a)  
         return a * a  
Answer
  1. Colon is missing at the end of function header.
  2. There is no error.
  3. The variable x is not defined.
  4. def keyword at the beginning and colon at the end of function header are missing.

The corrected function definitions are:

  1.  def main():  
         print("hello")
  2.  def func2():  
         print(2 + 3)  
  3.  def compute(x):  
         print (x * x)  
  4.  def square(a):  
         return a * a