English

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 - Computer Science (Python)

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:

  1. The ‘function call’ in line 4 is calling an invalid function. 'findValue()' is different from 'findvalue()' as Python is case sensitive.
  2. 'findValue()' function needs the value of at least 2 arguments val2 and val3 to work, which is not provided in the function call.
  3. 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?
Chapter 7: Functions - Exercise [Page 170]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 7 Functions
Exercise | Q 1. d) | Page 170
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×