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
- There is an indentation error in second line.
- The return statement should be indented inside function and it should not end with semicolon.
- Function call should not end with semicolon.
Answered By
5 Likes
Related Questions
Write the term suitable for following descriptions :
(a) A name inside the parentheses of a function header that can receive a value.
(b) An argument passed to a specific parameter using the parameter name.
(c) A value passed to a function parameter.
(d) A value assigned to a parameter name in the function header.
(e) A value assigned to a parameter name in the function call.
(f) A name defined outside all function definitions.
(g) A variable created inside a function body.
What do you understand by local and global scope of variables ? How can you access a global variable inside the function, if function has a variable with same name.
What are the errors in following codes ? Correct the code and predict output :
def Tot(Number) #Method to find Total Sum = 0 for C in Range (1, Number + 1): Sum += C RETURN Sum print (Tot[3]) #Function Calls print (Tot[6])
Find and write the output of the following python code :
def Call(P = 40, Q = 20): P = P + Q Q = P - Q print(P, '@', Q) return P R = 200 S = 100 R = Call(R, S) print(R, '@', S) S = Call(S) print(R, '@', S)