KnowledgeBoat Logo

Computer Science

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  
   

Python Functions

2 Likes

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 
    

Answered By

2 Likes


Related Questions