Advertisements
Advertisements
Question
Observe the following program carefully, and identify the error:
def findValue( vall = 1.1, val2, val3):
final = (val2 + val3)/ vall
print(final)
findvalue() #function call
Short Note
Solution
There are three errors in the given program:
- The ‘function call’ in line 4 is calling an invalid function. 'findValue()' is different from 'findvalue()' as Python is case sensitive.
- 'findValue()' function needs the value of at least 2 arguments val2 and val3 to work, which is not provided in the function call.
- As 'vall' is already initialized as 'vall = 1.0', it is called 'Default parameter' and it should be always after the mandatory parameters in the function definition. i.e. def findValue(val2, val3, vall = 1.0) is the correct statement.
shaalaa.com
Arguments and Parameters
Is there an error in this question or solution?
APPEARS IN
RELATED QUESTIONS
Differentiate between the following with the help of an example:
Argument and Parameter
Assertion (A): If the arguments in function call statement match the number and order of arguments as defined in the function definition, such arguments are called positional arguments.
Reasoning (R): During a function call, the argument list first contains default argument(s) followed by the positional argument(s).
Predict the output of the following code:
def Changer (P, Q=10):
P=P/Q
Q=P%Q
return P
A=200
B=20
A=Changer(A,B)
print(A,B,sep='$')
B=Changer(B)
print(A,B sep='$', end='# # #')