12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications மின்னணு தரவு பரிமாற்றம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிக பாதுகாப்பு அமைப்புகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின்னணு செலுத்தல் முறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications திறந்த மூல கருத்துருக்கள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு வடமிடல் Sample Question Papers Study Material - QB365 Set A

Published on: 03/12/2019
Python Functions
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
A with local scope can be accessed only within the block
keyword
variable
function
integer
2.
Which of the following statement causes your function to exit?
break
pass
return
3.
Non-keyword variable arguments are called
List
Tuples
Dictionaries
Arguments
4.
What will be the output if the return has no argument?
No
Return
None
End
5.
Which of the following keyword is used to define the function testpython(): ?
define
pass
def
while
6.
Write a note on return statement syntax.
7.
What are arguments? What are the types?
8.
Write the output of the following program.
9.
How to set the limit for recursive function? Give an example.
10.
What is base condition in recursive function?
11.
How python takes a default value in the function call? Explain with an example.
12.
Write the advantages of user-defined functions.
13.
What are the points to be noted while defining a function?
14.
Write a Python code to check whether a given year is leap year or not.
15.
16.
Write a python program to find HCF of two numbers using recursion.
17.
Explain different types arguments used in python with an example.
1.
(a)
keyword
2.
(d)
return
3.
(b)
Tuples
4.
(c)
None
5.
(c)
def
6.
Syntax of return :
return [expression list]
This statement can contain expression which gets evaluated and the value is returned. If there is no expression in the statement or the return statement itself is not present inside a function, then the function will return the None object.
7.
Arguments are used to call a function and there are primarily 4 types of functions. They are: Required arguments, Keyword arguments, Default arguments and Variable-length arguments.
8.
Example:
def hello():
print ("hello - Python")
return
print (hello())
Output:
hello - Python
None
9.
(i) Python stops calling recursive function after 1000 calls by default.
(ii) So, it also allows you to change the limit using sys.setrecursionlimit (limit_value).
Example:
import sys
sys.setrecursionlimit(3000)
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
print(fact (2000))
10.
(i) A recursive function calls itself.
(ii) The condition that is applied in any recursive function is known as base condition.
(iii) A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.
11.
(i) In Python the default argument is an argument that takes a default value if no value is provided in the function call.
(ii) The following example uses default arguments, that prints default salary when no argument is passed.
(iii) Example:
def printinfo( name, salary = 3500):
print ("Name: ", name)
print ("Salary: ", salary)
return
printinfo("Mani")
When the above code is executed, it produces the following output
Output:
Name: Mani
Salary: 3500
When the above code is changed as print info("Ram", 2000) it produces the following output:
Output:
Name: Ram
Salary: 2000
12.
Advantages of User-defined Functions
(i) Functions help us to divide a program into modules. This makes the code easier to manage.
(ii) It implements code reuse. Every time you need to execute a sequence of statements, all you need to do is to call the function.
(iii) Functions, allows us to change functionality easily, and different programmers can work on different functions.
13.
When defining functions there are multiple things that need to be noted;
(i) Function blocks begin with the keyword "def" followed by function name and parenthesis ().
(ii) If any input parameters are present should be placed within these parentheses when you define a function.
(iii) The code block always comes after colon(:) and is indented.
(iv) The statement "return [expression]" exits a function, optionally passing back an expression to the caller. A "return" with no arguments is the same as return None.
14.
Code:
n=int(input("Enter the year"))
if(y%4==0):
print ("Leap Year")
else:
print ("Not a Leap Year")
Output:
Enter the year 2012
Leap Year
15.
16.
# python program to find HCF
def HCF (x,y):
if(x > y):
s = y
else:
s = x
for I inrange (1, s + 1):
if ((x % I = = 0) and (y% i = = 0)):
hcf = i
return hcf
x = int (input ("Enter Number 1"))
y = int (input ("Enter Number 2"))
print (HCF (x, y))
17.
(i) Required Arguments:
"Required Arguments" are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. Atleast one parameter to prevent syntax errors to get the required output.
(ii) Example:
def printstring(str):
print ("Example - Required arguments")
print (str)
return
# Now you can call printstring() function
printstring ("Welcome")
Output:
Example - Required arguments
Welcome
(iii) When the above code is executed, it produces the following error.
Traceback (most recent call last):
File "Req-arg.py", line 10, in
printstring()
TypeError: printstring() missing 1 required positional argument: 'str'
(iv) Instead of printstring() in the above code if we use printstring ("Welcome") then the output is
Output:
Example - Required arguments
Welcome
Keyword Arguments:
Keyword arguments will invoke the function after the parameters are recognized by their parameter names. The value of the keyword argument is matched with the parameter name and so, one can also put arguments in improper order (not in order).
(ii) Example:
def printdata (name):
print ("Example-1 Keyword arguments")
print ("Name :":name)
return
# Now you can call printdatat() function
printdata(name = "Gshan")
(iii) When the above code is executed, it produces the following output:
Output:
Example-1 Keyword arguments
Name:Gshan
Default Arguments:
In Python the default argument is an argument that takes a default value if no value is provided in the function call. The following example uses default arguments, that prints default salary when no argument is passed.
Example:
def printinfo( name, salary = 3500):
print ("Name: ", name)
print ("Salary: ", salary)
return
printinfo("Mani")
(iii) When the above code is executed, it produces the following output
Output:
Name: Mani
Salary: 3500
(iv) When the above code is changed as print info("Ram,":2000) it produces the following output:
Output:
Name: Ram
Salary: 2000
Syntax - Variable-Length Arguments:
(i) def function_name(*args):
function_body
return_statement
(ii) Example:
def printnos (*nos):
for n in nos:
print(n)
return
# now invoking the printnos() function
print ('Printing two values')
printnos (1,2)
print ('Printing three values')
printnos (10,20,30)
Output:
Printing two values
1
2
Printing three values
10
20
30
12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications களப்பெயர் முறைமை (DNS) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு எடுத்துக்காட்டுகள் மற்றும் நெறிமுறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications கணினி வலையமைப்பு ஓர் அறிமுகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications PHP-உடன் MySQL-ஐ இணைத்தல் Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards