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: 05/09/2022
QB365 provides a detailed and simple solution for every Possible Creative Questions in Class 12 Computer Science Subject - Python Functions , English Medium. It will help Students to get more practice questions, Students can Practice these question papers in addition to score best marks.
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.
Create a program to specify global variable and local variable in same code and also with same name.
2.
With an example program, how will you modify and changing global variables from inside a function using the global keyword?
3.
What is local variable and what is global variable? Differentiate the method of access the variable by using example program.
4.
Define scope of variables. What are the rules for local variable and global keywords in Python?
5.
Explain in detail about return statement and give an example program.
6.
Define lambda function-Write its syntax and Give an example, explain in detail.
7.
What is anonymous function? Write its syntax and give an example program.
8.
Explain in detail about various functional arguments with its example.
9.
Explain how you will call a function and passing a parameters in function?
10.
Write a python program to find Fibonacci series of n terms using recursion.
11.
Write a python program to find HCF of two numbers using recursion.
12.
Explain different types arguments used in python with an example.
1.
Using Global and Local variables in same code:
x = 8 #x is a global variable.
def loc( ):
global x
y = "local"
x = x * 2
print (x)
print (y)
loc( )
Output:
16
local
We declare x as global and y as a local variable in the function loc( )
After calling the function loc( ) , the value of x becomes 16 because we used, x = x*2.Print the value of local variable y i.e., local.
Example:
Global variable and Local variable with same name:
x = 5
def loc( ):
x = 10
print ("local x:",x)
loc( )
print ("local x:",x)
Output:
local x: 10
global x: 5
local x: 10, is called the local scope of the variable
global x: 5, is called the global scope of the variable.
2.
Modifying Global variable from inside the function:
c = 1 # global variable
def add():
c = c + 2 # increment c by 2
print(c)
add ( )
Output:
Unbound Local Error: local variable 'c' referenced before assignment.
Without using the global keyword we cannot modify the global variable inside the function but we can only access the global variable.
Example:
Changing Global Variable From Inside a Function using global keyword
x = 0 # global variable
def add ( ):
global x
x = x + 5 # increment by 2
print ("Inside add() function x value is :", x)
add()
print ("In main x value is :", x)
Output:
Inside add() function x value is : 5
In main x value is : 5
(v) In the above program, x is defined as a global variable. Inside the add() function, global keyword is used for x and we increment the variable x by 5. Now We can see the change on the global variable x outside the function i.e the value of x is 5.
3.
1. Local scope:
A variable declared inside the function's body or in the local scope is known as local variable.
Example:1
Create a Local Variable
def loc():
y=0 # local scope
print(y)
loc ( )
Output:
0
Example: 2
Accessing local variable outside the scope
def loc():
y = "local"
loc()
print(y)
When we run the code, the output shows the error:
Name Error: name 'y' is not defined.
2. Global scope:
A variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function/block.
Example:
Accessing global Variable From Inside a Function
c = 1 #-global variable
def add():
print(c)
adder
Output:
1
4.
Scope of variable refers to the part of the program, where it is accessible, i.e., area where the variables refer (use). The scope holds the current set of variables and their values. The two types of scopes - local scope and global scope.
Local Scope: A variable declared inside the function's body or in the local scope is known as a local variable.
Rules of local variable:
(i) A variable with a local scope can be accessed only within the function/block that it is created in.
(ii) When a variable is created inside the function/block, the variable becomes local to it.
(iii) A local variable only exists .while the function is executing.
(iv) The formate arguments are also local to function.
Global scope: A variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function/block.
Rules of global Keyword:
The basic rules for global keywords in Python are:
(i) When we define a variable outside a function, it's global by default. You don't have to use global keywords.
(ii) We use a global keyword to read and write a global variable inside a function.
(iii) Use of global keyword outside a function has no effect.
5.
1. The return statement causes your function to exit and returns a value to its caller. The point of functions, in general, is to take inputs and return something.
2. The return statement is used when a function is ready to return a value to its caller. So, only one re[urn statement is executed at run time even though the function contains multiple returns statements.
3. Any number of 'return statements are allowed in a function definition but only one of them is executed at run time.
Syntax of return:
return [expression list]
4. This statement can contain an expression that 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.
Example:
#return statement
def usr_abs (n):
if n>=0:
return n
else:
return-n
# Now invoking the function
x = int (input ("Enter a number:"))
print (usr_abs(x))
Output 1:
Enter a number: 25
25
Output 2:
Enter a number: -25
25
6.
In Python, an anonymous function is a function that is defined without a name. While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called as lambda functions.
Uses:
1. Lambda function is mostly used for creating small and one-time anonymous functions.
2. Lambtla functions are mainly used in combination with the functions like filter ( ), maps ( ) and reduce ( ).
3. Lambda function can take any number of arguments expression. Lambda function can only access global and must return one value in the form of variables and variables in its parameter list.
Syntax of Anonymous Functions:
The syntax for anonymous functions is as follows:
lambda [argument(s)]: expression
Example:
sun = lambda arg1, arg2: arg1 + arg2
print ('The Sum is :', sum(30, 40)
print ('The Sum is :', sum(-30, 40)
Output:
The Sum is: 70
The Sum is: 10
7.
In Python, an anonymous function is a function that is defined without a name. While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called as lambda functions.
Uses:
1. Lambda function is mostly used for creating small and one-time anonymous functions.
2. Lambtla functions are mainly used in combination with the functions like filter ( ), maps ( ) and reduce ( ).
3. Lambda function can take any number of arguments expression. Lambda function can only access global and must return one value in the form of variables and variables in its parameter list.
Syntax of Anonymous Functions:
The syntax for anonymous functions is as follows:
lambda [argument(s)]: expression
Example:
sun = lambda arg1, arg2: arg1 + arg2
print ('The Sum is :', sum(30, 40)
print ('The Sum is :', sum(-30, 40)
Output:
The Sum is: 70
The Sum is: 10
8.
Arguments are used to call a function. They are:
1. Required arguments
2. Keyword arguments
3. Default arguments
4. Variable-length arguments.
1. 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. We need exactly one parameter to prevent syntax errors to get the required output.
Example:
def print - string(str):
print ("Example - Required arguments")
print - (str)
return
# Now we can call print string ( ) function.
Print string ( )
When the above code is executed, it produces the error
Traceback (most recent call last):
File "Reg- arg.py",line 10, in
print string ( )
Type Error: print string( ) missing required positional arguments: 'str'
Instead of print string ( ), use print string ("Welcome") then the output is
Example - Required arguments
Welcome.
2. 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).
Example:
def print data (name):
print ("Example-1Keyword arguments")
print ("Name :":name)
return
# Now you can call print data() function
print data(name = "Gshan")
When the above code is executed, it produces the following output:
Output:
Example-1 Keyword arguments
Name: Gshan
3. 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 tries default arguments, that print default salary when no argument is passed.
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
4. Variable-length arguments:
In some instances, we might need to pass more arguments than have already been specified. Going back to the function to redefine it can be a tedious process. variable - length arguments can be used instead. These are not specified in the function's definition and an asterisk (*) is used to define such argument.
Example:
def sum (x,y,z):
print("sum of three nos:", x+y+z)
sum (5,10,15,20,25).
True Error: Sum 0 takes 3 positional arguments but 5 were given.
9.
When we call the "hello ( )" Function, the program. displays the string as output:
hello - Python
Alternatively, we can call the "hello( )" function within the print ( ) functions as in the example.
Example:
def hello ( ):
print ("hello - Python'')
return
print (hello ( ))
If the return has no argument, "None" will be displayed as the last statement of the output.
hello - Python
None
1. Parameters or arguments can be passed to function.
2. def function- name (parameter(s) separated by comma):
3. The parameters that we place in the parenthesis will be used by the function itself. We can pass all sorts of data to the functions. Here is an example program that defines a function that helps to pass parameters into the function.
Example:
#assumew = 3 and h = 5
def area(w, h):
return w*h
print (area (3,5))
4. The above code assigns the width and height values to the parameters w and h. These parameters are used in the creation of the function "area''.
5. The value of 3 and 5 are passed to w and h respectively, the function will return 15 as output.
10.
# program to find fibonacci series
def fibo (n):
if n < = 1:
return n
else:
return (fibo (n - 1) + fibo (n - 2))
n = int (input ("Enter How manu terms"))
for i in range (n):
print (fibo (i))
11.
# 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))
12.
(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