Computer Science

What are the errors in following codes ? Correct the code and predict output :

total = 0;
    def sum(arg1, arg2): 
    total = arg1 + arg2;
    print("Total :", total) 
return total;
sum(10, 20);
print("Total :", total)

Python

Python Functions

13 Likes

Answer

total = 0
def sum(arg1, arg2):  
    total = arg1 + arg2
    print("Total :", total) 
    return total
sum(10, 20)
print("Total :", total)
Total : 30
Total : 0

Working

  1. There is an indentation error in second line.
  2. The return statement should be indented inside function and it should not end with semicolon.
  3. Function call should not end with semicolon.

Answered By

5 Likes


Related Questions