Ncert solutions for class 11 Computer Science Python Chapter 10 Functions are prepared by CBSE student eCARE expert to score good marks in class 11. Classes 11 Computer Science Python Chapter 10 Functions contain many topics which are very important to score good in class 11. There are some important topic mentioned below:
Here are simple rules to define a function in Python.
? Function blocks begin with the keyword def followed by the function name and Parentheses ()
? Any input parameters or arguments should be placed within these parentheses.
? The first statement of a function can be an optional statement – the documentation string of the function or docstaing.
? he code block within every function start with color(:) and is indented.
? The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return none.
? A high order function accepts one or more functions as input and returns a new function. Sometimes it is required to use function as data.
? To make high order function, one need the import functools module.
? The functools.partial() function is used often for high order function.
What is a Python module ? What is its significance ? .
A ‘module’ is a chunk of python code that exists in its own (.pu) file and is intended to be used by python code outside iteself. Modules allow one to fundle together code in a form in which it can easily be used later.
The modules can be ‘imported’ in other programs so the function and other definitions in imported modules becomes availabe to code that imports them.
“Python has certain functions that you can readily use without having to write any special code.” What type of functions are these ?
The pre-defined functions that are always available for use are known as python’s built-in functions. For example :
len (), type (), int (), raw-input () etc.
What is the utility of built-in function help () ?
Python’s built in function help ( ) is very useful. When it is provided with a program-name or a module-name or a function-name as an argument, it displays the documentation of the argument as help. It also displays the docstrings within its passed-argument’s definition. For example :
will display the documentation related to module math.
What is the utility of Python standard library’s math module and random module ?
Math module is used for math related functions that work with all number types except for complex numbers, radom module is used for different random number generator functions.
What is raw_input?
It is a function which takes a string (e.g., a question) as argument, writes the string to the terminal window, halts the program and lets the user write in text on the keyboard, and then the text is returned to the calling code as a string object.
What value will be return by log(x[, base])?
With one argument, return the natural logarithm of x (to base e).
With two arguments, return the logarithm of x to the given base, calculated as log(x) log(base)
Define pow(x, y) function in Python ?
Return x raised to the power y.. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. If both x and y are finite, x is negative, and y is not an integer then pow(x, y) is undefined, and raises ValueError.
Determine what is printed by the following program listinput.py,
list1 = eval(raw_input(‘Give a list:’))
list2 = eval(raw_input(‘Give another list:’))
print list1 + list2
When the program is running as follows:
Unix/DOS > python listinput.py
Give a list: ‘[1,2]’
Give another list: “[3,4]”
What will be the output of this program?
a = 20.3
b = ‘Python’
c = ‘”Python”‘
d = 21
print isinstance(a, float),
print isinstance(b, (str, int)),
print isinstance(c, (str, str)),
print isinstance(d, (float, str))
True, True, True, False.
Write any Python expression which is a valid input argument to the following program?
input = eval(raw_input(‘Value:’))
print ‘You typed’, value
Given the program
from scitools.StringFunction import
formula = sys.argv
f = StringFunction(formula)
Will this input work?
Unix/DOS > python function.py ‘t**2’
No, This input will not work