Topics Covered
Theory-based questions for Working with functions Class 12
- A function is a set of instructions or subprograms that are used to fulfil the user’s need.
- In other words, a function is a bunch of code which performs a specific task.
- A function is used to do a specific task and divide the large program into smaller blocks.
- A function is a small unit of a program that processes the data and often returns a value.
- To make the program easy
- Divide the large program into a small block of codes
- Reduce the lines of code
- Easy to update
- Start the code with def followed by function name and supply input through the parameters.
- Write the set of statements to be executed in the program.
- Call the function to invoke or execute the statements.
- Function header: It starts with def followed by the function name and required parameters. Parameters are the input variables written into brackets. These parameters are supplied in the function calling statement.
- Function Body: This is the main part of a program. It contains the main block of the program. The set of instructions such as calculations, logical comparisons etc is written here in this part. It ends with a return statement. Indentation is very important for the function body.
- Function calling statement: This is the final part of a function. It invokes the function and returns the output as instructed into the function body.
Part | Description |
---|---|
Function Header | Always starts with the “def” keyword followed by the function name and its parameters, and ends with a colon (:) |
Parameters | Variablessupplied in brackets of the function header |
Function Body | Block of statements/instructions that define the action performed by the function, indentation must be followed |
Indentation | White space at the beginning of every statement with the same block |
Function Calling | writing function name including parameter values |
- Write the function name.
- Supply the values of the parameters, if any.
- A function in the python program is called by a function call statement
- To call a function, write the function name followed by parameter values in brackets
- A block of statements executed in the execution frame
- When a function is called, an execution frame is created and controls the transfer
- Within the execution frame, the statements written in the function body are executed and return a value or execute the last statement
- Python follows top to bottom approach for executing program
- Comments are ignored in execution
- If python notices function definition with a def statement it just executes the function header line and skips all statements in the function body these statements execute when a function will be called
- Built-in Functions: Pre-defined functions of python such as len(), type(), input() etc.
- Functions defined in modules: Functions defined in particular modules, can be used when the module is imported. A module is a container of functions, variables, constants, and classes in a separate file which can be reused.
- User-Defined Functions: Function created by the programmer
- The module can be imported in two ways
- import statement: Used to import the entire module. EX. import math
- from statement : import all functions or the selected one. EX. from random import randint
Parameters | Arguments |
---|---|
These are specified during the function definition. | Values passed during the function call. |
They are also known as formal parameters. | They are also known as actual parameters. |
The values passed as parameters are local variables and are assigned values of the arguments during the function call. | Every argument is assigned to a parameter when the function is defined. |
These variables help in the complete execution of the function. | These variables are passed to the function for execution. |
The values contained by these parameters can only be accessed from function return statements or if the scope of these parameters is made global. | The arguments are accessible throughout the program depending upon the scope of the variable assigned. |
- Positional Arguments: Arguments passed to a function in correct positional order, no. of arguments must match with no. of parameters required.
- Default Arguments: Assign a default value to a certain parameter, it is used when the user knows the value of the parameter, default values are specified in the function header. It is optional in the function call statement. If not provided in the function call statement then the default value is considered. Default arguments must be provided from right to left.
- Key Word Arguments: Keyword arguments are the named arguments with assigned values being passed in the function call statement, the user can combine any type of argument.
- Variable Length Arguments: It allows the user to pass as many arguments as required in the program. Variable-length arguments are defined with the * symbol.
Global Variable: A variable that is declared in top-level statements is called a global variable. To access the value of a global variable user need to write a global keyword in front of the variable in a function.
Local Variable: A name declared in a specific function body is called a local variable.
1. An argument list must contain positional arguments followed by any keyword argument.
2. Keyword arguments should be taken from the required arguments preferably.
3. Value of the argument can’t be specified more than once.
Ex.:
cal_discount(amt=500,rate=10) or cal_discount(rate=10,amt=500)
In the next section of Working with Functions Class 12 we are going through the output questions.
Output Questions Working with functions Class 12
print(b)
b = 5
0 @ 6 @ 7 @ 8 @ 9 @
0 @ 6 @ 7 @
In the next section Working with functions Class 12 questions and answers, we are going through error-based questions.
Error-based questions working with functions class 12 computer science
print(Sum[5])
Follow this link to read notes:
- Python Functions Basic Class 12 Computer Science
- Python Functions insights for Computer Science Class 12
In the next section of Working with functions Class 12 questions and answers you will get the programs based Working with functions topic.
Python Practical programs with solutions Working with functions Class 12
In the below link you will get some solved programs on Working with functions Class 12. This will help you prepare your practical file. This link also contains Type C Practical questions from Sumita Arora Text Book exercise or Sumita Arora Book Questions with solutions for the chapter Working with functions Class 12.
Watch this video for solutions to Output and error questions of the chapter Working with Functions Class 12:That’s all from the chapter Working with Functions Class 12 questions and answers. If you have any doubts or queries feel free to ask in the comment section.
Thank you for reading the Working with Functions Class 12 questions and answers. Visit my blog website for more articles like Working with functions Class 12 questions answers.
Give your valuable suggestions in the comment section for Working with Functions Class 12 questions and answers.
Please provide answers too
Answers will be provided shortly
Output questions and error questions solution provided now. Just check latest post
thank you for the uploads…plz upload chapter wise question bank
Where are the answers?
Check out this post.
https://www.tutorialaicsip.com/2020/05/assignment-solution-working-with.html
Thanks
page not found. please provide answers
Will be improved