[Type A] Chapter – 3 Class 12 CS – Sumita Arora Assignment | Q/A

Here is class 12 computer science Unit 3 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 3 and for all chapters here.

Watch all tutorials for chapter 3: Python Revision Tour.

Q1: A program having multiple functions is considered better designed than a program without any functions. Why?

A program having multiple function satisfy the following parameter :
1. Increase reusability of code.
2. Decrease the complexity of the program.
3. Clean and understandable structure of programme increases.
4. Ease of debugging of program.

Q2: What all information does a function header give you about the function?
  1. Number and type of parameter required to call function.
  2. Name of function to call upon.
  3. Idea about working of the function.
Q3: What do you understand by the flow of execution?

Flow of execution refers to flow in which the statement are executed in the program i.e. generally top to bottom during execution.

Function definition do not alter this order and the function is not taken into account of the execution till the function is called in the program.

def function_name(parameter):          
     .........
     return result  # after this next line of                       function call is executed


function_name(parameter) # direct to function definition 

Q4: What are the arguments ? What are the parameters ? How are these two terms different yet related? Give an example.

Argument is the keyword that is related to the time of function calls. Argument need to be provided while calling a function. For example calling an addition function need to pass two value to add and these values are called arguments.
Sum(5, 4) # here 5 and 4 is termed as argument.

Parameter is the keyword related to the function definition. Its defines the requirement of the values and type of that to act upon the function.
def Sum(a, b): # here a and b is named parameter

Hence, we can say that argument is values of parameter while calling a function.

Q5: What is the utility of:
(i) default arguments
(ii) keyword arguments

(i) Default argument allows us to have safe end with function calling and also a standard parameter tuning while function definition. If the function is called without the argument, the argument gets its default value that is defined during function definition.

(ii) Keyword arguments in python is one of the method of parameter allocation after the positional arguments. It makes a more easy way of parameter value allocation by the naming of parameter.
Keyword arguments are included with a keyword and equals sign.

Q6: Explain with a code example the usage of default arguments and keyword arguments.
# Function definition is here
def Person(name, age = 35 ): #age default argument
   print "Name: ", name
   print "Age ", age
   return;

# Now calling function
Person(name="Abhi")
Person(age=50, name="Vishal") #keyword argument 
Person(50, "Vishal") # keyword argument is not used

As during the definition of function we defined age as 35 i.e. we defined a default value to age and this is termed as default argument. Such as during calling of function :
Case 1: No argument to age is passed hence default value 35 assigned to age.
Case 2: Age is given argument value 50, hence it will overlap default value 35.
Case 3: In this the function is called without the keyword argument.

Q7: Describe the different styles of functions in Python using appropriate examples.

There are basically three type of function in python

Built-infunction : These are globally defined function and always ready to use in python itself. For example len(), range(), type(), int() etc.

Module function : These are the function that are defined under specific module. To use then import of the module is important. For example : sum(), sqrt() in Math module, plot(), scatter() in matplotlib etc.

User Defined : These are the function that are defined by the user during the course of the program for specific use.

Q8: Describe the different styles of functions in Python using appropriate examples.

There are basically three type of function in python

Built-in-function : These are globally defined function and always ready to use in python itself. For example len(), range(), type(), int() etc.

Module function : These are the function that are defined under specific module. To use then import of the module is important. For example : sum(), sqrt() in Math module, plot(), scatter() in matplotlib etc.

User Defined : These are the function that are defined by the user during the course of the program for specific use.

Q9: Can a function return multiple values? How?

Yes, function in python can return multiple values easily in different form like as object, list, tuple, dictionary.

def swap(a, b): 
    c =a
     a, b=b, c
    return [a,b] 

The above code is for return multiple value by list.

Q10: What is the scope? What is the scope of resolving the rule of Python?

The part of program where data or code (variable) can be accessed is called scope of variable in python.

The scope resolution rule in python is known as LEGB rule i.e. Local, Enclosing, Global, Built-in. The two mainly are local and global scope.

Q11: What is the difference between local and global variables?

A local variable is just being access under the block of scope while the global variable can be assessed in the entire program.

a=2
def swap(a, b):
    c =a
    a, b = b, c
    return [a, b]
res = swap(3,4)
print(a)
print(c)

Here an is global variable hence print(a) will run but c is local variable that is access under swap function block that’s why print(c) will show error.

Q12: When is a global statement used? Why is its use not recommended?

Global statement is refers to the global variable that can be used in entire program and hence is used to get rid of again and again defining and increase reusability. Such as we defined pi =3.14 as globally to have same value in entire program.

It is not highly recommended because there can instance occur when global and local statement having same name then it will manipulate actual result of program.

Q13: Write the term suitable for the 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.

(a) Function declared argument.
(b) Keyword argument.
(c) Formal parameter.
(d) Default argument.
(e) Actual parameter.
(f) Global variable.
(g) Local variable.

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

You cannot copy content of this page