Get the most accurate TN Board Solutions for Class 12 Computer Science Chapter 07 Python Functions here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 12 Computer Science. Our expert-created answers for Class 12 Computer Science are available for free download in PDF format.
Detailed Chapter 07 Python Functions TN Board Solutions for Class 12 Computer Science
For Class 12 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 12 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 07 Python Functions solutions will improve your exam performance.
Class 12 Computer Science Chapter 07 Python Functions TN Board Solutions PDF
I. Choose the best answer (I Marks)
Question 1. A named blocks of code that are designed to do one specific job is called as
(a) Loop
(b) branching
(c) Function
(d) Block
Answer: (c) Function
In simple words: A function is like a small helper program that does one specific job. You give it a name so you can easily ask it to do that job whenever you need to.
๐ฏ Exam Tip: Remember that functions are named blocks of code, distinguishing them from unnamed loops or branching structures.
Question 2. A Function which calls itself is called as
(a) Built-in
(b) Recursion
(c) Lambda
(d) return
Answer: (b) Recursion
In simple words: When a function uses itself to solve a problem, it's called recursion. It's like a set of Russian dolls, where each doll contains a smaller version of itself.
๐ฏ Exam Tip: Understand that recursion involves a function calling itself, often to solve a problem by breaking it down into smaller, similar sub-problems.
Question 3. Which function is called anonymous un-named function PTA โ
(a) Lambda
(b) Recursion
(c) Function
(d) define
Answer: (a) Lambda
In simple words: A lambda function is a small, simple function that doesn't have a regular name. It's used for quick, one-time tasks without needing a full `def` statement.
๐ฏ Exam Tip: Associate 'anonymous' or 'un-named' functions directly with lambda functions, as this is their defining characteristic in Python.
Question 4. Which of the following keyword is used to begin the function block?
(a) define
(b) for
(c) class
(d) def
Answer: (d) def
In simple words: In Python, you start writing a new function using the special word `def`. It tells the computer that you are about to define a new function.
๐ฏ Exam Tip: Remember that `def` is the standard keyword for defining functions in Python, just like `for` is for loops and `class` is for classes.
Question 5. Which of the following keyword is used to exit a function block?
(a) define
(b) return
(c) finally
(d) def
Answer: (b) return
In simple words: The `return` keyword is used to stop a function from running and, if needed, send a value back to where the function was called. It's how a function gives its result.
๐ฏ Exam Tip: The `return` statement is crucial for functions to pass values back and to control when a function finishes its execution.
Question 6. While defining a function which of the following symbol is used.
(a) ; (semicolon)
(b) . (dot)
(c) : (colon)
(d) $ (dollar)
Answer: (c) : (colon)
In simple words: When you finish writing the function's name and its parts in Python, you must put a colon (`:`) right after it. This colon tells the computer that the actual code for the function is about to begin.
๐ฏ Exam Tip: In Python, a colon (`:`) is always used to mark the start of a new code block, like functions, loops, or conditional statements.
Question 7. In which arguments the correct positional order is passed to a function?
(a) Required
(b) Keyword
(c) Default
(d) Variable-length
Answer: (a) Required
In simple words: Required arguments must be given to a function in the exact order they are listed when the function was created. You cannot skip them or change their order.
๐ฏ Exam Tip: Positional arguments, often called 'required arguments', demand that you pass values in the exact sequence specified by the function definition.
Question 8. Read the following statement and choose the correct statement(s).
I) In Python, you don't have to mention the specific data types while defining function.
II) Python keywords can be used as function name.
(a) I is correct and II is wrong
(b) Both are correct
(c) I is wrong and II is correct
(d) Both are wrong
Answer: (a) I is correct and II is wrong
In simple words: Python is smart; you don't need to tell it if a variable is a number or text. But you cannot use Python's special reserved words (keywords like `def` or `for`) as names for your functions.
๐ฏ Exam Tip: Python is dynamically typed (no explicit type declaration for variables/functions), but it reserves keywords which cannot be used as identifiers.
Question 9. Pick the correct one to execute the given statement s successfully, if ............ : print (x, " is a leap year")
(a) x%2=0
(b) x%4==0
(c) x/4=0
(d) x%4=0
Answer: (b) x%4==0
In simple words: To check if a year is a leap year, one common rule is to see if it can be divided by 4 with no remainder. The `==0` checks for an exact match to zero.
๐ฏ Exam Tip: In programming, `==` is used for comparison (checking if two values are equal), while `=` is used for assignment (giving a value to a variable).
Question 10. Which of the following keyword is used to define the function testpython(): ?
(a) define
(b) for
(c) def
(d) while
Answer: (c) def
In simple words: To create a new function named `testpython` in Python, you must use the special word `def` right before its name. This is the standard way to declare a function.
๐ฏ Exam Tip: Always start your function definition with the `def` keyword, followed by the function name and parentheses, and end with a colon.
II. Answer the following questions (2 Marks)
Question 1. What is a function?
Answer: A function is a named group of code steps designed to do one specific task. If you need to do that same task many times in your program, you can simply call this named function. This helps keep your code organized and easy to reuse. It also makes your program easier to read and understand.
In simple words: A function is a piece of code that does a specific job and has a name. You can use it many times in your program.
๐ฏ Exam Tip: Focus on 'named block of code' and 'specific task' and 'reusability' as key phrases when defining a function.
Question 2. Write the different types of functions.
Answer: The different types of functions are:
1. User-defined functions: These are functions created by the user to perform specific tasks.
2. Built-in functions: These are functions that are already provided by the programming language (like Python).
3. Lambda functions: These are small, anonymous (un-named) functions.
4. Recursive functions: These are functions that call themselves to solve a problem.
In simple words: Functions can be ones you make, ones already in the computer, small unnamed ones, or ones that call themselves.
๐ฏ Exam Tip: Clearly list and briefly define each type of function to show a complete understanding of function categories.
Question 3. What are the main advantages of function?
Answer: The main advantages of using functions are:
- Functions help avoid writing the same code again and again, which means you can reuse your code a lot.
- They make your program easier to divide into smaller, manageable parts, improving its modularity. This structure makes the code easier to test and debug.
In simple words: Functions save work by letting you use the same code many times. They also make your program neat and easier to understand.
๐ฏ Exam Tip: Remember 'code reusability' and 'modularity' (making the program easier to manage) as the primary benefits of using functions.
Question 4. What is meant by scope of variable? Mention its types.
Answer: The scope of a variable refers to the part of the program where that variable can be accessed or used. It defines where a variable "lives" in your code. The scope also holds the current set of variables and their values during a program's execution. The two main types of scopes are:
- Local scope: Variables defined inside a function.
- Global scope: Variables defined outside any function.
In simple words: Variable scope means where in your code a variable can be seen and used. There are two types: local (inside a function) and global (outside any function).
๐ฏ Exam Tip: Define scope as the 'accessibility' of a variable and list both local and global as its types for full marks.
Question 5. Define global scope.
Answer: A variable with a global scope can be used anywhere in the entire program. You create a global variable by defining it outside of any function or code block. These variables are generally accessible from any part of the code, making them useful for values needed broadly.
In simple words: Global scope means a variable can be used anywhere in your program. You make it global by writing it outside of any function.
๐ฏ Exam Tip: The key idea of global scope is that the variable is defined *outside* a function and can be accessed from *anywhere* in the program.
Question 6. What is the base condition in a recursive function
Answer:
- A recursive function calls itself repeatedly. If there were no stop condition, this process would continue forever, leading to an "infinite iteration."
- The specific condition that stops a recursive function from calling itself again is called the base condition.
- Every recursive function must have a base condition; otherwise, it will run continuously without ending, like an infinite loop, eventually causing an error.
In simple words: A recursive function keeps calling itself. The base condition is the rule that tells the function when to stop calling itself and give an answer, so it does not run forever.
๐ฏ Exam Tip: Emphasize that the base condition is essential for stopping recursion and preventing infinite loops; it provides the final, non-recursive answer.
Question 7. How to set the limit for recursive function? Give an example.
Answer: Python allows you to change the maximum number of times a recursive function can call itself using `sys.setrecursionlimit()`. This function takes an integer value which is the new limit. It is important to set a reasonable limit to prevent stack overflow errors, as each recursive call uses memory.
Example:
import sys
sys.setrecursionlimit(3000)
def fact (n):
if n == 0:
return 1
else:
return n * fact (n - 1)
print (fact (2000))In simple words: You can set a new limit for how many times a recursive function can call itself in Python using `sys.setrecursionlimit()`. This helps stop it from running too many times and causing problems.
๐ฏ Exam Tip: State the function `sys.setrecursionlimit()` and provide a clear, working example of how to use it to modify the recursion depth.
III. Answer the following questions (3 Marks)
Question 1. Write the rules of the local variable.
Answer: Here are the rules for local variables:
- A variable defined with a local scope can only be used and accessed within the specific function or block of code where it was created.
- When you create a variable inside a function or a code block, that variable automatically becomes local to that specific part of the code.
- A local variable only exists and holds its value while the function it belongs to is actively running. Once the function finishes, the local variable is removed.
- Any arguments that are passed into a function are also treated as local variables within that function.
In simple words: A local variable can only be used inside the function where it's made. It only stays alive while that function is working. Things you send to a function also become local variables inside it.
๐ฏ Exam Tip: The key rules for local variables are that they are defined inside a function, are accessible only within that function, and exist only while the function is executing.
Question 2. Write the basic rules for a global keyword in python.
Answer: Here are the basic rules for using the `global` keyword in Python:
- If you define a variable outside of any function, it is automatically a global variable. You usually don't need to use the `global` keyword for these unless you want to change them inside a function.
- We use the `global` keyword when we want to change the value of a global variable from *inside* a function. It signals that you are referring to the global version of the variable, not creating a new local one.
- Using the `global` keyword outside of a function has no special effect because variables defined there are already global by default.
In simple words: Variables made outside functions are global. We use the `global` keyword when we want to change a global variable's value from inside a function. Using `global` outside a function does nothing special.
๐ฏ Exam Tip: Remember that `global` is primarily used *inside* a function to modify a global variable, not just to read it or declare it outside functions.
Question 3. What happens when we modify the global variable inside the function?
Answer: When you modify a global variable from inside a function (by explicitly using the `global` keyword), the change will also affect the value of that global variable outside the function. This means the updated value will be seen and used across your entire program. It's important to be careful when doing this, as it can make code harder to track.
In simple words: If you change a global variable inside a function using the `global` keyword, its value will also change everywhere else in your program.
๐ฏ Exam Tip: Clearly state that modification of a global variable inside a function (with `global` keyword) impacts its value globally across the program.
Question 4. Differentiate ceil() and floor() function?
Answer:
| Ceil() | Floor() |
|---|---|
| The `ceil()` function gives you the smallest whole number that is greater than or equal to the number you provide. | The `floor()` function gives you the largest whole number that is less than or equal to the number you provide. |
In simple words: `ceil()` finds the next whole number up (or the number itself), while `floor()` finds the next whole number down (or the number itself).
๐ฏ Exam Tip: Remember that `ceil()` always rounds up to the next integer, and `floor()` always rounds down to the previous integer, regardless of the decimal value.
Question 5. Write a Python code to check whether a given year is leap year or not
Answer: Here is a Python code to check if a given year is a leap year:
n = int(input("Enter any year"))
if (n % 4 == 0):
print ("Leap year")
else:
print ("Not a Leap year")This code first asks the user to enter a year. Then, it checks if that year is perfectly divisible by 4. If it is, the year is considered a leap year according to one basic rule. Output:
Enter any year 2001
Not a Leap year
In simple words: This code asks for a year, then checks if it can be divided by 4 with no leftover. If yes, it's a leap year. If no, it's not.
๐ฏ Exam Tip: While the basic rule for a leap year is divisibility by 4, more complex rules involve divisibility by 100 and 400 for certain centuries. For basic questions, `year % 4 == 0` is often sufficient.
Question 6. What is a composition in functions?
Answer: Function composition happens when the output (value) from one function is used as the input (argument) for another function. This process is often done in a nested way, where one function call is placed inside another. This allows you to combine simple functions to create more complex operations.
- The value returned by one function can be used as an argument for another function in a nested way; this is called composition.
- For example, if you want to take a number or an expression as input from the user, you first get the input string using the `input()` function and then use the `eval()` function to calculate its actual value.
In simple words: Function composition means using the result of one function as the starting point for another function. It's like putting functions together, one inside the other.
๐ฏ Exam Tip: Understand function composition as chaining functions, where the 'output of F1 becomes the input of F2', enabling complex operations from simple building blocks.
Question 7. How recursive function works?
Answer: A recursive function solves a problem by calling itself with smaller parts of the problem until a simple case (the base condition) is met. This simple case then provides a direct answer, and the function unwinds, building up the final solution. The working principle involves three main points:
- A recursive function is started or called by some external code or another function.
- If the base condition of the recursion is met, the program stops the recursive calls, provides a meaningful output, and then exits that part of the function.
- If the base condition is not met, the function performs some necessary calculations or processing and then calls itself again with modified inputs to continue the recursion.
In simple words: A recursive function works by calling itself over and over again with a smaller problem. It stops when it hits a "base condition," gives an answer, and then uses that answer to solve the bigger problem step by step.
๐ฏ Exam Tip: When explaining recursion, clearly outline the process: function calls itself, checks base condition, processes if not base, calls itself again, until base is hit and results propagate back.
Question 8. What are the points to be noted while defining a function?
Answer: When defining a function, keep these important points in mind:
- All function code blocks must begin with the `def` keyword, followed by the function's name and then a pair of parentheses `()`.
- Any parameters or arguments that the function needs to receive should be placed inside these parentheses when you define the function.
- The actual code block of the function always starts after a colon (`:`) and must be indented (usually with four spaces or a tab).
- The `return` statement, `return [expression]`, is used to exit a function and optionally send a value back to the code that called it.
- If a `return` statement is used without any arguments, it is the same as writing `return None`, meaning the function does not explicitly send back any value.
In simple words: When you make a function, start with `def` and its name, put inputs in `()`, add a colon `:`, and indent the code. Use `return` to give an answer or simply exit.
๐ฏ Exam Tip: Focus on the syntax essentials: `def` keyword, parentheses for parameters, colon to start the block, indentation, and the role of the `return` statement.
IV. Answer the following questions (5 Marks)
Question 1. Explain the different types of function with an example.
Answer: Functions are blocks of code designed to do a specific job, and they help make programs organized and reusable. Here are the main types of functions:
| Functions | Description |
|---|---|
| User-defined functions | Functions that are created and defined by the users themselves. |
| Built-in functions | Functions that are already included and available within Python. |
| Lambda functions | Small, anonymous (un-named) functions that can be defined in a single line. |
| Recursive functions | Functions that call themselves to solve a problem. |
def welcome():
print("Welcome to Python")
return2. Built-in functions:
These are functions that come pre-installed with Python, so you can use them right away without writing their code. They are part of Python's standard library.
Example:x = 20
y = -23
print('First number = ', x)
print('Second number = ', y)Output:
First number = 20
Second number = 23
3. Lambda function:
Lambda functions are small, unnamed functions typically used for simple, one-time tasks. They are often used with other functions like `filter()`, `map()`, and `reduce()`.
Syntax of Lambda function (Anonymous Functions):
`lambda [argument(s)]: expression`
Example:sum = 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
4. Recursive function:
A recursive function is one that calls itself to solve a problem. It works by breaking a problem into smaller parts until it reaches a simple base case, and then it builds the solution back up.- A recursive function calls itself repeatedly. This process would go on forever if not stopped by a specific condition. Such a process is called infinite iteration.
- The condition that stops a recursive function from calling itself is known as a base condition.
- Every recursive function must have a base condition; otherwise, it will keep running like an infinite loop.
def fact(n):
if n == 0:
return 1
else:
return n * fact (n-1)
print (fact (0))
print (fact (5))Output:
1
120In simple words: There are four main types of functions: user-made ones (user-defined), ones built into Python (built-in), small unnamed ones (lambda), and ones that call themselves (recursive). Each type helps do different jobs in a program.
๐ฏ Exam Tip: For a 5-mark question, define each function type, provide its syntax (if applicable), and include a small example for each, ensuring the explanation is clear and concise.
Question 2. Explain the scope of variables with an example.
Answer:Scope of Variables:
The scope of a variable tells you which parts of your program can see and use that variable. It defines the 'area' where a variable is valid and accessible. We can also say that the scope holds the current set of variables and their values during program execution.
The two main types of scopes are local scope and global scope.
(I) Local Scope:
A variable that is created inside the body of a function or within a specific local scope is called a local variable. These variables can only be used within the function where they are defined.
Rules of local variable:
1. A variable with local scope can be used only inside the function or block where it was created.
2. When a variable is created inside a function or block, it becomes local to that block.
3. A local variable only exists while its function is running.
4. The arguments passed to a function are also considered local to that function.
Example: Create a Local Variable
def loc ():
y = 0 # local scope
print (y)
loc ()Output:
0
(II) Global Scope:
A variable with a global scope can be used anywhere in the program, meaning it's accessible from any part of the code. It is created by defining a variable outside of any function or block of code.
Rules of global Keyword:
The basic rules for using the `global` keyword in Python are:
1. When you define a variable outside a function, it's global by default. You don't need to use the `global` keyword to declare it.
2. We use the `global` keyword when we want to read and then change a global variable from inside a function.
3. Using the `global` keyword outside of a function has no effect because variables defined there are already global.
Example: Global variable and Local variable with same namex = 5
def loc ():
x = 10
print ("local x:", x)
loc ()
print ("global x:", x)Output:
local x: 10
global x: 5
In the code above, we used the same name 'x' for both a global variable and a local variable. When we print the variable `x` inside the `loc()` function, it shows 'local x: 10' because the local scope inside the function takes precedence. When we print `x` outside the function, it shows 'global x: 5', referring to the global variable.In simple words: Variable scope means where a variable can be seen. Local variables are only inside a function, while global variables can be seen everywhere. We use the `global` keyword to change a global variable from inside a function.
๐ฏ Exam Tip: Clearly define both local and global scopes, list their rules, and provide an example that shows how a variable with the same name can exist in both scopes.
Question 3. Explain the following built-in functions.
(a) id()
(b) chr()
(c) round ()
(d) type()
(e) pow()
Answer:
| Function | Description | Example / Output |
|---|---|---|
id() | This function gives the unique "identity" of an object, which is like its specific memory address. This is helpful for understanding how Python manages objects. | x=15y='a'print('address of x is:', id (x))print ('address of y is:', id(y))Output: address of x is: 1357486752address of y is: 13480736 |
chr(i) | This returns the character that matches a given ASCII (American Standard Code for Information Interchange) value. It does the opposite of the ord() function. | c=65d=43print(chr(c))print(chr(d))Output: A+ |
round(number [,ndigits]) | This function rounds a number to the nearest whole number. You can also tell it how many decimal places to round to. | x=17.9y=22.2z=-18.3print('x value is rounded to', round(x))print('y value is rounded to', round(y))print ('z value is rounded to', round(z))Output: x value is rounded to 18y value is rounded to 22z value is rounded to -18 |
type(object) | This function tells you what kind of object is passed to it, such as a number, text, or true/false value. It helps identify the data structure. | x=15.2y='a's=trueprint(type(x))print(type(y))print(type(s))Output: <class 'float' ><class 'str' ><class 'bool' > |
pow(a,b) | This function calculates the power of a number, meaning 'a' raised to the power of 'b' (a**b). It's a fundamental operation in many mathematical contexts. | a=5b=2c=3.0print(pow(a,b))print(pow(a,c))print(pow(a+b,3))Output: 25125.0343 |
In simple words: Python has many built-in functions like
id(), chr(), round(), type(), and pow() that help you do common tasks easily. Each one does a special job, like finding a number's memory spot or rounding a value.๐ฏ Exam Tip: When explaining built-in functions, always include its purpose, basic usage, and a clear, simple example to show how it works.
Question 4. Write a Python code to find the L.C.M. of two numbers.
Answer:
Here is the Python code to calculate the L.C.M. (Least Common Multiple) of two numbers:
# Python Program to find the L.C.M. of two input numberdef compute_lcm(x, y): # choose the greater number if x > y: greater = x else: greater = y while (True): if((greater % x == 0) and (greater % y == 0)): lcm = greater break greater += 1 return lcm
num1=int(input("Enter first number="))num2=int(input("Enter second number="))print("The L.C.M. is", compute_lcm(num1, num2))
Output:Enter first number=8Enter second number=4The L.C.M. is 8
In simple words: This code finds the smallest number that can be divided evenly by two other numbers. It checks numbers starting from the larger of the two inputs until it finds one that both numbers can divide into.
๐ฏ Exam Tip: For LCM problems, remember to find the largest of the two numbers first and then use a loop to check for divisibility, incrementing the larger number until the condition is met.
III. Answer The Following Questions (3 Marks)
Question 1. Write the rules of the local variable.
Answer:
A local variable has rules that dictate where and when it can be used within a program. These variables are important for isolating data within specific parts of your code.
- A variable with a local scope can only be used inside the function or block where it was created.
- When a variable is made inside a function or a block of code, it becomes local to that specific part.
- A local variable only exists for as long as the function is running. Once the function finishes, the variable is removed.
- The arguments passed into a function also act as local variables for that function.
In simple words: A local variable can only be used inside the specific function or code block where it was made. It only lives while that function runs.
๐ฏ Exam Tip: To score full marks, clearly state that local variables are confined to their function scope and cease to exist after function execution.
Question 2. Write the basic rules for a global keyword in python.
Answer:
The global keyword in Python is used to manage variables that are accessible from anywhere in the program. Understanding its rules is key to controlling variable scope.
- When you create a variable outside of any function, it is global by default. You do not need to use the
globalkeyword explicitly for its initial definition. - The
globalkeyword is necessary when you want to read or change a global variable from inside a function. - Using the
globalkeyword outside of a function has no special effect because variables defined at the top level are already global.
In simple words: Variables made outside functions are global by default. You use the
global keyword inside a function if you want to change a global variable or refer to it clearly.๐ฏ Exam Tip: Highlight that global is primarily used inside functions to modify global variables, not to declare them initially at the top level.
Question 3. What happens when we modify the global variable inside the function?
Answer:
If you modify a global variable inside a function using the global keyword, that change will also affect the variable's value outside the function. This allows functions to impact the program's overall state.
In simple words: If you change a global variable inside a function, its new value will be seen and used everywhere else in the program.
๐ฏ Exam Tip: Emphasize that changes to a global variable within a function (using the global keyword) are reflected globally, showing its program-wide impact.
Question 4. Differentiate ceil() and floor() function?
Answer:
The ceil() and floor() functions are used to round numbers to the nearest integer, but they do so in opposite directions. They are often used in mathematics and programming to handle decimal values.
| Ceil() | Floor() |
|---|---|
The ceil() function returns the smallest whole number that is greater than or equal to the given value. | The floor() function returns the largest whole number that is less than or equal to the given value. |
In simple words:
Ceil() rounds a number up to the next whole number, while floor() rounds it down to the previous whole number.๐ฏ Exam Tip: Remember ceil() is like looking up at the ceiling (rounds up) and floor() is like looking down at the floor (rounds down).
Additional Questions And Answers
I. Choose The Best Answer
Question 1. The name of the function is followed by ............
(a) ()
(b) []
(c) <>
(d) { }
Answer: (a) ()
In simple words: In Python, when you write a function name, it is always followed by parentheses, even if it doesn't take any inputs.
๐ฏ Exam Tip: Recall the basic syntax for calling or defining a function in Python; it always includes parentheses.
Question 2. Which of the following provides better modularity for your python application
(a) tuples
(b) function
(c) dictionaries
(d) control structures
Answer: (b) function
In simple words: Using functions helps you break your code into smaller, organized parts, making your program easier to manage and understand.
๐ฏ Exam Tip: Understand that functions are core to modular programming, enabling code reuse and easier debugging, which directly contributes to better modularity.
Question 3. How many types of functions are there in python?
(a) 3
(b) 2
(c) 4
Answer: (c) 4
In simple words: Python generally uses four main types of functions to help organize and perform tasks in your code.
๐ฏ Exam Tip: Be ready to name the four types of functions: user-defined, built-in, lambda, and recursive functions.
Question 4. Functions that call itself are known as
(a) User-defined
(b) Built-in
(c) Recursive
(d) Lambda
Answer: (c) Recursive
In simple words: A special kind of function that keeps calling itself to solve a problem is called a recursive function.
๐ฏ Exam Tip: The key characteristic of a recursive function is its self-referential call; always link "calling itself" to "recursive."
Question 5. If the return has no argument, ............ will be displayed as the last statement of the output.
(a) No
(b) None
(c) Nothing
(d) No value
Answer: (b) None
In simple words: If a function finishes without returning any specific value, Python automatically returns 'None'.
๐ฏ Exam Tip: Remember that Python functions always return a value; if nothing is specified, it defaults to None.
Question 6. In which of the following the number of arguments in the function call should match exactly with the function definition?
(a) Keyword arguments
(b) Required arguments
Answer: (b) Required arguments
In simple words: For required arguments, you must give the exact number of inputs that the function is expecting, no more and no less.
๐ฏ Exam Tip: Distinguish required arguments by their strict positional and count matching with the function definition.
Question 7. Which of the following is used to define variable-length arguments?
(a) $
(b) *
(c) #
(d) //
Answer: (b) *
In simple words: In Python, the asterisk symbol (`*`) is used before a parameter name to allow a function to accept any number of extra arguments.
๐ฏ Exam Tip: Associate the asterisk (*) with variable-length arguments, allowing a function to accept a flexible number of inputs.
Question 8. What is the symbol used to denote variable-length arguments?
(a) +
(b) *
(c) &
(d) ++
Answer: (b) *
In simple words: The star symbol (`*`) is how you tell Python that a function can take many extra inputs, not just a fixed number.
๐ฏ Exam Tip: This question directly tests syntax; ensure you know the asterisk symbol for variable-length arguments.
Question 9. Which function can take any number of arguments and must return one value in the form of an expression?
(a) user-defined
(b) recursive
(c) default
(d) lambda
Answer: (d) lambda
In simple words: A 'lambda' function is a small, unnamed function that can take many inputs but always gives back only one result as a single expression.
๐ฏ Exam Tip: Key characteristics of lambda functions are their single-expression return, anonymous nature, and ability to accept multiple arguments.
Question 10. How many return statement is executed at runtime?
(a) 2
(b) multiple
(c) 3
(d) 1
Answer: (d) 1
In simple words: Even if a function has many 'return' statements, only one of them will actually run and give a value when the function is used.
๐ฏ Exam Tip: Remember that function execution stops as soon as the first return statement is encountered, so only one return value can be produced.
Question 11. How many types of scopes in Python?
(a) 3
(b) 4
(c) many
(d) 2
Answer: (d) 2
In simple words: In Python, variables can live in two main places: either locally inside a function or globally throughout the whole program.
๐ฏ Exam Tip: The two primary types of scope in Python are local and global; be ready to explain each.
Question 12. Lambda functions cannot be used in combination with ............
(a) Filter
(b) Map
(c) Print
(d) Reduce
Answer: (c) Print
In simple words: Lambda functions are used for calculations and expressions, but you cannot directly use them with 'print' because 'print' is a statement, not an expression.
๐ฏ Exam Tip: Understand that lambda functions are designed for single expressions and do not support statements like print directly within their definition.
Question 13. Function blocks begin with the keyword ............
(a) Fun
(b) Definition
(c) Function
(d) Def
Answer: (d) Def
In simple words: To start writing a new function in Python, you always begin with the special word 'def', followed by the function's name.
๐ฏ Exam Tip: The def keyword is fundamental for defining functions in Python; ensure you know its correct usage.
Question 14. ............ function can only access global variables.
(a) user-defined
(b) recursive
(c) Lambda
(d) return
Answer: (c) Lambda
In simple words: A Lambda function is a small function that can use variables defined outside of it, which are known as global variables.
๐ฏ Exam Tip: While lambda functions can access global variables, they typically don't allow assignment to them; they are often used for simple operations that can read from their enclosing scope.
Question 15. Find the correct one:
(a) Global keyword outside the function has no effect
(b) Global keyword outside the function has an effect
Answer: (a) Global keyword outside the function has no effect
In simple words: When you use the 'global' keyword outside of a function, it doesn't change anything because variables defined there are already global by default.
๐ฏ Exam Tip: The global keyword is primarily functional within a function to modify a global variable, making it redundant and ineffective when used outside a function.
II. Answer The Following Questions (2 And 3 Marks)
Question 1. Define nested blocks?
Answer:
A nested block is a section of code that is placed inside another block of code. This structure helps organize logic and control program flow.
When you have a block of code within another block, it's called a nested block. For example, if the first block's statement is indented by one tab space, the statement of the second (nested) block will be indented by two tab spaces, showing its deeper level of structure.
In simple words: A nested block is like having a smaller code section tucked inside a bigger one, shown by more indentation.
๐ฏ Exam Tip: Explain nested blocks using indentation as a key visual cue, clarifying how one code block sits inside another for logical organization.
Question 2. Differentiate parameters and arguments.
Answer:
Parameters and arguments are related but different terms used when working with functions. They both deal with how information is passed into a function.
| Parameters | Arguments |
|---|---|
| Parameters are the variable names listed inside the parentheses in the function's definition. | Arguments are the actual values that are sent to the function when it is called. |
In simple words: Parameters are like placeholders in a function's recipe, while arguments are the actual ingredients you put in when you use the recipe.
๐ฏ Exam Tip: Clearly state that parameters are part of the function definition, while arguments are the values passed during a function call.
Question 3. Differentiate parameters and arguments?
Answer:
Parameters are the variables defined when you create a function, acting as placeholders for incoming data. Arguments, on the other hand, are the specific values that are actually sent to those parameters when the function is run.
In simple words: Parameters are the names given in the function definition, and arguments are the real values passed to those names when you use the function.
๐ฏ Exam Tip: Focus on the distinction: parameters are for defining, arguments are for calling a function. They represent the function's input mechanism.
Question 4. Write the syntax of variable-length arguments.
Answer:
Variable-length arguments allow a function to accept any number of arguments, which is useful when you don't know beforehand how many inputs there will be. The syntax includes a special symbol before the argument name.
The syntax for variable-length arguments in a function definition is:def function_name(*args): function_body return_statement
In simple words: To make a function take any number of inputs, you put a star `*` before the argument name in its definition.
๐ฏ Exam Tip: Make sure to include the asterisk (*) before args in the syntax, as this is the defining characteristic of variable-length arguments.
Question 5. What are the methods used to parse the arguments to the variable length arguments?
Answer:
When using variable-length arguments, there are two main ways to send data to the function. These methods give flexibility in how you provide inputs.
You can send arguments to variable-length arguments using two methods:
- Non-keyword variable arguments (using
*args) - Keyword variable arguments (using
**kwargs, though not explicitly mentioned as such here, the term is related)
In simple words: You can give inputs to variable-length arguments in two ways: either as simple items or by using keywords to name them.
๐ฏ Exam Tip: The two methods are non-keyword (positional) and keyword arguments, often denoted by *args and **kwargs respectively.
Question 6. What is a local variable?
Answer:
A local variable is a type of variable that is defined and used only within a specific function or block of code. It cannot be accessed from outside that defined area. This helps keep variables organized and prevents conflicts.
In simple words: A local variable is a variable that only exists and can be used inside the specific part of the program where it was created, like inside a function.
๐ฏ Exam Tip: Define a local variable by its scope, emphasizing that it's confined to the function or block where it's declared.
Question 7. What are the two methods of passing arguments in variable-length arguments?
Answer:
When dealing with functions that can take an unknown number of arguments, there are two common ways to pass these arguments. These methods provide different levels of organization and clarity.
In Python, you can pass arguments to variable-length arguments using two main methods:
1. Non-keyword variable arguments (like *args, which collects all extra positional arguments into a tuple).
2. Keyword variable arguments (like **kwargs, which collects all extra keyword arguments into a dictionary).
In simple words: You can pass arguments to functions that take many inputs in two ways: either by just listing them (non-keyword) or by giving each one a name (keyword).
๐ฏ Exam Tip: Differentiate between non-keyword arguments (positional, collected by *args) and keyword arguments (named, collected by **kwargs) for variable-length argument handling.
Question 8. Write a note on return statement?
Answer:
The return statement is a powerful command in functions that determines what value a function sends back to the part of the code that called it. It also signifies the end of a function's execution.
1. The return statement causes your function to stop running and sends a value back to the code that asked for it. Functions are generally designed to take inputs and then provide some output.
2. A return statement is used when a function is ready to send a value back. Only one return statement is executed during runtime, even if the function has multiple return statements defined in its code.
3. Any number of return statements are allowed within a function definition, but only one of them will actually execute at runtime.
In simple words: The return statement makes a function give back a value and then stop running. Even if you write many 'return' lines, only one will ever work.
๐ฏ Exam Tip: Highlight that return both exits a function and passes a value back, and crucially, only one return statement can execute per function call.
Question 9. Write a note on min (), max () and sum () with an example
Answer:
Python provides several built-in functions to perform common operations on collections of numbers, such as finding the minimum, maximum, or total sum. These functions simplify data analysis tasks.
Function: min ()
Description: This function finds and returns the smallest value in a given list or collection of items. It is very useful for quick data comparisons.
Syntax: min (list)
Example:My List = [21,76,98,23]print ('Minimum of My List:', min(My List))
Output:Minimum of My List: 21
Function: max ()
Description: This function finds and returns the largest value in a list or collection. It helps in quickly identifying the highest element within a dataset.
Syntax: max (list)
Example:My List = [21,76,98,23]print ('maximum of My List :', max(my list))
Output:Maximum of My List: 98
Function: sum ()
Description: This function calculates and returns the total sum of all the numeric values in a list. It is commonly used for aggregation.
Syntax: sum (list)
Example:My List = [21,76,98,23]print (Sum of My List :', sum(My List))
Output:Sum of My List :218
In simple words: The min() function finds the smallest number in a list, max() finds the largest, and sum() adds all the numbers together.
๐ฏ Exam Tip: When writing about min(), max(), and sum(), always provide their purpose, basic syntax, and a clear example with sample data and output.
Question 10. Write a note on the floor, ceil () and sqrt () with an example
Answer:
Python's math module provides several useful functions for numerical operations, including rounding and square roots. These functions are important for various mathematical computations.
Function: floor ()
Description: This function returns the largest whole number that is less than or equal to the input value x. It effectively rounds down the number.
Syntax: math.floor (x)
Example:x=26.7y=-26.7print (math.floor (x))print (math.floor (y))
Output:26-27
Function: ceil ()
Description: This function returns the smallest whole number that is greater than or equal to the input value x. It effectively rounds up the number.
Syntax: math.ceil (x)
Example:x=26.7y=-26.7print (math.ceil (x))print (math.ceil (y))
Output:27-26
Function: sqrt ()
Description: This function calculates and returns the square root of the input value x. It's important to note that x must be a positive number (greater than or equal to zero).
Syntax: math.sqrt (x)
Example:a=49b= 25print (math.sqrt (a))print (math.sqrt (b))
Output:7.05.0
In simple words: The floor() function rounds a number down, ceil() rounds it up, and sqrt() finds its square root. These are useful math tools.
๐ฏ Exam Tip: Remember to import the math module before using functions like floor(), ceil(), and sqrt(), and always provide clear examples for each function.
Question 11. Write a note on the format () with an example.
Answer:
The format() function in Python is a versatile tool for creating well-structured strings by inserting values into predefined text templates. It allows for precise control over how data is displayed.
Function: format ()
Description: This function creates formatted output based on a specified format. It takes a value and a format specification to customize how that value appears in a string.
- Binary format: It displays the number as a base-2 (binary) representation.
- Octal format: It displays the number as a base-8 (octal) representation.
- Fixed-point notation: It shows the number as a fixed-point decimal. The default precision (number of decimal places) is 6.
Syntax:
format (value [,format_spec])Example:
x=14y=25print ('x value in binary :',format(x,'b'))print ('y value in octal :',format(y,'o'))print('y value in Fixed-point no :',format(y,'.6f'))Output:
x value in binary: 1110y value in octal: 31y value in Fixed-point no : 25.000000In simple words: The
format() function helps you show numbers and text in different styles, like converting a number to binary or controlling how many decimal places it has.๐ฏ Exam Tip: Practice using different format specifiers (like 'b' for binary, 'o' for octal, '.6f' for fixed-point) with the format() function to demonstrate its flexibility.
III. Answer The Following Questions (5 Marks)
Question 1. Explain different types of arguments used in python with an example.
Answer:
In Python, arguments are values that are passed into a function when it is called. There are four primary types of arguments, each with specific rules for how they are passed and handled within the function. Understanding these types is crucial for writing flexible and robust functions.
There are primarily four types of arguments that can be used in Python functions:
1. Required arguments
2. Keyword arguments
3. Default arguments
4. Variable-length arguments
Required Arguments:
- "Required Arguments" are the arguments that must be passed to a function in the correct order (positional order).
- The number of arguments provided when calling the function must exactly match the number of parameters defined in the function.
- At least one parameter is needed to prevent syntax errors and get the expected output.
Example:
def printstring(str): print ("Example โ Required arguments") print (str) return# Now you can call printstring() functionprintstring ("Welcome")Output:
Example โ Required arguments WelcomeWhen the above code is executed, it produces the following error if no argument is passed:
Traceback (most recent call last): File "Req-arg.py", line 10, in < module > printstring()TypeError: printstring() missing 1 required positional argument: 'str'Keyword Arguments:
- Keyword arguments call the function by recognizing its parameters through their names, not just their position.
- The value of the keyword argument is matched with the parameter name. This means you can pass arguments in any order, not just the positional one.
Example:
def printdata (name): print ("Example-1 Keyword arguments") print ("Name : ",name) return# Now you can call printdata() functionprintdata(name = "Gshan")When the above code is executed, it produces the following output:
Output:
Example-1 Keyword argumentsName: GshanDefault Arguments:
- In Python, a default argument is one that automatically takes a specific value if no value is given for it when the function is called.
- The following example uses default arguments. It prints a default salary if no salary is provided.
Example:
def printinfo(name, salary = 3500): print ("Name:", name) print ("Salary: ", salary) returnprintinfo("Mani")When the above code is executed, it produces the following output:
Output:
Name: ManiSalary: 3500When the above code is changed to
printinfo("Ram",salary=2000), it produces the following:Output:
Name: RamSalary: 2000Variable-Length Arguments:
- Sometimes, a function needs to take more arguments than were initially specified in its definition.
- These arguments are not explicitly named in the function's definition. Instead, an asterisk (`*`) is used to indicate that the function can accept a variable number of positional arguments.
- These types of arguments are known as Variable-Length arguments.
Syntax:
def function_name(*args): function_body return_statementExample:
def printnos (*nos): for n in nos: print(n) return# now invoking the printnos() functionprint ('Printing two values')printnos (1,2)print ('Printing three values')printnos (10,20,30)Output:
Printing two values12Printing three values102030In simple words: Python functions can take inputs in four main ways: required (must give all inputs in order), keyword (name the inputs), default (use a pre-set value if no input is given), and variable-length (take any number of extra inputs using `*`).
๐ฏ Exam Tip: For a 5-mark question, define each argument type, provide its syntax or a clear explanation of its mechanism, and include a concise Python example with expected output.
III. Answer the following questions (5 Marks)
Question 1. Explain different types of arguments used in python with an example.
Answer: Python functions can use four main types of arguments: required, keyword, default, and variable-length arguments. Each type helps in making functions more flexible and reusable for various programming needs.
1. Required Arguments:
These arguments must be passed to a function in the exact order they are defined. The number of arguments in the function call must match the number of parameters defined in the function. If there is a mismatch, the program will show a syntax error.
Example:
`def printstring(str_val):`
` print ("Example โ Required arguments")`
` print (str_val)`
` return`
`printstring ("Welcome")`
Output:
`Example โ Required arguments Welcome`
`Welcome`
2. Keyword Arguments:
Keyword arguments allow you to pass values to a function by referring to the parameter names. This means you can specify arguments out of their original positional order. Python matches the value to the correct parameter using its name.
Example:
`def printdata (name):`
` print ("Example-1 Keyword arguments")`
` print ("Name : ", name)`
` return`
`printdata(name = "Gshan")`
Output:
`Example-1 Keyword arguments`
`Name : Gshan`
3. Default Arguments:
A default argument has a preset value. If no value is provided for this argument during the function call, it uses its default value. If a value is provided, it overrides the default.
Example:
`def printinfo(name, salary = 3500):`
` print ("Name:", name)`
` print ("Salary: ", salary)`
` return`
`printinfo("Mani")`
Output:
`Name: Mani`
`Salary: 3500`
To change the salary value, you can call the function like this:
`printinfo("Ram", 2000)`
Output:
`Name: Ram`
`Salary: 2000`
4. Variable-Length Arguments:
Sometimes, you might need to pass a varying number of arguments to a function, more than what was initially specified. These arguments are handled using an asterisk (*) before the parameter name in the function definition. This allows the function to accept any number of additional arguments.
Syntax:
`def function_name(*args):`
` function_body`
` return_statement`
Example:
`def printnos (*nos):`
` for n in nos:`
` print(n)`
` return`
`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`
In simple words: Arguments are how you give information to a function. Required ones must be given in order. Keyword ones let you name what you are giving, so order doesn't matter. Default ones have a fallback value if you don't provide one. Variable-length arguments let you send many items, and the function handles them all.
๐ฏ Exam Tip: When explaining argument types, always include a small code example for each to clearly demonstrate how it works in Python. This shows a practical understanding beyond just definitions.
Free study material for Computer Science
TN Board Solutions Class 12 Computer Science Chapter 07 Python Functions
Students can now access the TN Board Solutions for Chapter 07 Python Functions prepared by teachers on our website. These solutions cover all questions in exercise in your Class 12 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.
Detailed Explanations for Chapter 07 Python Functions
Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 12 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 12 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.
Benefits of using Computer Science Class 12 Solved Papers
Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 12 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 07 Python Functions to get a complete preparation experience.
FAQs
The complete and updated Samacheer Kalvi Class 12 Computer Science Solutions Chapter 7 Python Function is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest TN Board curriculum.
Yes, our experts have revised the Samacheer Kalvi Class 12 Computer Science Solutions Chapter 7 Python Function as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.
Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 12 Computer Science Solutions Chapter 7 Python Function will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 12 Computer Science. You can access Samacheer Kalvi Class 12 Computer Science Solutions Chapter 7 Python Function in both English and Hindi medium.
Yes, you can download the entire Samacheer Kalvi Class 12 Computer Science Solutions Chapter 7 Python Function in printable PDF format for offline study on any device.