CBSE/Karnataka PU Board PUC I Chapter 7 Functions in Python:

 


 [Follow herefor daily coding insights.

PREVIOUS CHAPTER QUESTION BANK CLICK BELOW

CHAPTER 1 

CHAPTER 2

CHAPTER 3

CHAPTER 4

CHAPTER 5 

CHAPTER 6 

[NOTE: Kindly cross check answers once from other source also, Quantity and Quality of answers also kindly check before use, specially 5 marks answers are not sufficient kindly add from your side, this gives just quick review]


CBSE/Karnataka PU Board PUC I Chapter 7

Functions in Python:

50 MCQ :

  1. What is a function in Python?
    A. A variable
    B. A named block of code
    C. A data type
    D. A module
    Answer: B

  2. Which keyword is used to define a user-defined function?
    A. func
    B. def
    C. function
    D. define
    Answer: B

  3. Functions help to achieve which of the following?
    A. Modularity
    B. Redundancy
    C. Complexity
    D. Error
    Answer: A

  4. What is returned by a function with no return statement?
    A. Zero
    B. None
    C. True
    D. False
    Answer: B

  5. Which is NOT an advantage of using functions?
    A. Readability
    B. Reusability
    C. Difficult debugging
    D. Code organization
    Answer: C

  6. What is the default value returned by print()?
    A. The printed text
    B. None
    C. 0
    D. True
    Answer: B

  7. Which is NOT a standard library function in Python?
    A. input()
    B. print()
    C. sort()
    D. user_func()
    Answer: D

  8. What statement calls a function named 'myFunc'?
    A. run myFunc()
    B. use myFunc()
    C. myFunc()
    D. call myFunc
    Answer: C

  9. Arguments passed in a function call are assigned to ____ in the definition.
    A. parameters
    B. values
    C. fields
    D. variables
    Answer: A

  10. Which statement is true for local variables?
    A. Accessible anywhere
    B. Only in function defined
    C. In all modules
    D. In built-in functions
    Answer: B

  11. Function names must follow rules for _______.
    A. Constants
    B. Identifiers
    C. Operators
    D. Comments
    Answer: B

  12. Which of the following is optional in a function definition?
    A. Colon
    B. Parameters
    C. Function name
    D. Indentation
    Answer: B

  13. In Python, return statement does what?
    A. Ends loop
    B. Skips value
    C. Sends value to caller
    D. Deletes variable
    Answer: C

  14. What is a void function?
    A. Returns a value
    B. Prints output
    C. Returns None
    D. Has no arguments
    Answer: C

  15. How many values can Python return from a function?
    A. Only one
    B. Multiple via tuple
    C. None
    D. One integer
    Answer: B

  16. What does the def keyword do?
    A. Calls function
    B. Ends function
    C. Defines function
    D. Returns result
    Answer: C

  17. What happens if you call a function before it's defined?
    A. It works
    B. NameError
    C. SyntaxError
    D. None
    Answer: B

  18. Which function calculates the factorial of a number?
    A. fact()
    B. calcFact()
    C. factorial()
    D. pow()
    Answer: B

  19. What is the scope of a variable defined inside a function?
    A. Global
    B. Local
    C. Universal
    D. Restricted
    Answer: B

  20. Which statement imports a module in Python?
    A. define module
    B. import
    C. add module
    D. include module
    Answer: B

  21. What is the name of the parameter receiving an argument?
    A. value
    B. reference
    C. parameter
    D. argument
    Answer: C

  22. Which will correctly return area and perimeter from a single function?
    A. return area + perimeter
    B. return (area, perimeter)
    C. print area, perimeter
    D. save area, perimeter
    Answer: B

  23. A function with default parameter values can skip arguments:
    A. True
    B. False
    Answer: A

  24. Module containing math functions is called:
    A. maths
    B. math
    C. statistics
    D. numbers
    Answer: B

  25. Which function rounds up a float to the next integer?
    A. ceil()
    B. round()
    C. floor()
    D. int()
    Answer: A

  26. What is a module in Python?
    A. A number
    B. A collection of functions
    C. An operator
    D. A string
    Answer: B

  27. What does random.randint(1,5) return?
    A. A float
    B. An int between 1 and 5
    C. A string
    D. Error
    Answer: B

  28. Which function is used to find the mean in the statistics module?
    A. statistics.mean()
    B. mean()
    C. average()
    D. sum()
    Answer: A

  29. What happens if you import a module twice?
    A. Loads twice
    B. Loads only once
    C. Throws error
    D. Reloads variables
    Answer: B

  30. What will print(pow(2,3)) output?
    A. 8
    B. 6
    C. 9
    D. 7
    Answer: A

  31. How is the floor value found?
    A. Using math.ceil()
    B. Using math.floor()
    C. math.int()
    D. floor()
    Answer: B

  32. What does the id() function return?
    A. Type of variable
    B. Memory address
    C. Variable name
    D. Reference
    Answer: B

  33. Which operator concatenates strings?
    A. +
    B. &
    C. |
    D. ,
    Answer: A

  34. What is the built-in function for input?
    A. user()
    B. input()
    C. read()
    D. enter()
    Answer: B

  35. Function header ends with:
    A. ;
    B. .
    C. :
    D. ,
    Answer: C

  36. What happens if parameters are missing in a call without defaults?
    A. Uses 0
    B. Error
    C. Ignores
    D. Assumes None
    Answer: B

  37. What can a function parameter be?
    A. Only int
    B. Any data type
    C. Only string
    D. Only list
    Answer: B

  38. What is the result of print(max(3, 7, 5))?
    A. 3
    B. 5
    C. 7
    D. Error
    Answer: C

  39. What does the len() function do?
    A. Adds numbers
    B. Counts elements
    C. Deletes strings
    D. Multiplies values
    Answer: B

  40. Which can be used to import only specific functions from a module?
    A. from … import …
    B. define … functions
    C. only … import …
    D. func … import …
    Answer: A

  41. If you need only the sqrt and ceil from math module, which is correct?
    A. import math.sqrt, math.ceil
    B. from math import sqrt, ceil
    C. import math
    D. math.sqrt, math.ceil
    Answer: B

  42. A function can be called from:
    A. Only main
    B. Another function
    C. Only outside
    D. Only inside
    Answer: B

  43. What is the output of print(type("hello"))?
    A. str
    B. int
    C. float
    D. list
    Answer: A

  44. What is a function call in Python?
    A. Defining function
    B. Passing control to function
    C. Ending program
    D. Raising error
    Answer: B

  45. Function arguments and parameters must be in:
    A. Same order
    B. Any order
    C. Ignored order
    D. Only reversed
    Answer: A

  46. What is modular programming?
    A. Using many variables
    B. Dividing program into blocks
    C. Writing long code
    D. Ignoring errors
    Answer: B

  47. What is the output of divmod(7,2)?
    A. (3, 1)
    B. 3.5
    C. (1, 3)
    D. (2, 5)
    Answer: A

  48. What function sorts a list in ascending order?
    A. list.sort()
    B. sort()
    C. sorted()
    D. arrange()
    Answer: A

  49. What does a docstring describe?
    A. A module or function
    B. A variable
    C. An error
    D. A loop
    Answer: A

  50. What is a built-in function?
    A. Custom written function
    B. Predefined function provided by Python
    C. Variable
    D. Loop
    Answer: B

1 mark questions with answers

  1. What keyword is used to define a function in Python?
    Answer: def

  2. What is a function in Python?
    Answer: A named group of instructions that performs a specific task.

  3. What is the output if a function doesn’t have a return statement?
    Answer: None

  4. What is modular programming?
    Answer: Dividing a program into independent blocks (functions).

  5. Name the function used to accept user input in Python.
    Answer: input()

  6. Can a function have no parameters?
    Answer: Yes

  7. What does a return statement do in a function?
    Answer: Returns value to the caller and exits the function.

  8. What type of value can be returned by a function?
    Answer: Any type (number, string, tuple, etc.)

  9. Which function returns the length of a list?
    Answer: len()

  10. What is the scope of a variable defined inside a function?
    Answer: Local scope

  11. How do you call a function named myFun?
    Answer: myFun()

  12. What is a default parameter?
    Answer: A pre-assigned value for a parameter in a function.

  13. Name one built-in mathematical module in Python.
    Answer: math

  14. What does print() function do?
    Answer: Displays output to the screen.

  15. What keyword makes a variable refer to the global scope inside a function?
    Answer: global

  16. Which operator is used to concatenate strings?
    Answer: +

  17. What is the docstring in Python?
    Answer: Documentation string for function/module.

  18. Is it possible to return multiple values from a function?
    Answer: Yes (using tuple).

  19. How many times is a module loaded if imported twice?
    Answer: Only once

  20. What is a parameter in Python?
    Answer: Variable in function definition that receives argument value.

2 mark questions with answers

  1. What is modular programming?
    Answer:
    Dividing a program into separate blocks (functions) that perform specific tasks, making the code organized and reusable.

  2. Explain the use of the 'def' keyword in Python with an example.
    Answer:
    'def' starts a function definition. Example:

python
def greet(): print("Hello")
  1. What is a parameter and what is an argument in a function?
    Answer:
    A parameter is a variable in the function definition; an argument is the value passed to that parameter during a function call.

  2. Can a function return multiple values? How?
    Answer:
    Yes, by returning a tuple. Example:

python
def minmax(a, b): return min(a,b), max(a,b)
  1. Write a user-defined function to add two numbers.
    Answer:

python
def add(x, y): return x + y
  1. Describe the use of the return statement in Python functions.
    Answer:
    It sends the function’s result back to the caller, optionally exiting the function.

  2. What are default parameters?
    Answer:
    Parameters with preset values, used if no argument is given in the function call.

  3. Differentiate between global and local variables.
    Answer:
    Global: Defined outside functions, accessible everywhere. Local: Defined inside functions, accessible only there.

  4. Is it necessary for a function to always return a value?
    Answer:
    No, functions can be void (no return value).

  5. What does the len() function do?
    Answer:
    Returns the number of items in a sequence (e.g. list or string).

  6. How do you import the math module in Python?
    Answer:
    Using import math.

  7. Show with code how to return the area and perimeter of a rectangle from a function.
    Answer:

python
def rect(l, w): return l*w, 2*(l+w)
  1. Give the function header for a function to calculate compound interest.
    Answer:

python
def compound_interest(principal, rate, time, n):
  1. What is the use of docstring in a function/module?
    Answer:
    Acts as documentation for describing the function or module.

  2. What happens when a function call precedes its definition in code?
    Answer:
    Raises a NameError, since Python requires functions to be defined before they are called.

  3. Describe the scope of a variable inside a function.
    Answer:
    It is local to that function and not accessible outside.

  4. How can you import only sqrt and ceil from the math module?
    Answer:
    from math import sqrt, ceil

  5. Show the syntax for a function with no parameters and no return value.
    Answer:

python
def display(): print("Hello")
  1. How do you call a function named 'show' with parameter 'x' as 5?
    Answer:
    show(5)

  2. What will print(max(5, 7, 2)) display?
    Answer:
    7

Here are 20 three-mark (3 marks) questions with detailed answers from "kecs107.pdf" (Functions in Python):

  1. Explain with example the concept of modular programming.
    Answer: Modular programming divides code into independent blocks called functions. Example:

python
def add(x, y): return x + y def subtract(x, y): return x - y

In a program, these functions can be reused and called as needed, improving organization and reusability.

  1. Write a user-defined function to find the mean of a list of values.
    Answer:

python
def myMean(myList): total = sum(myList) count = len(myList) mean = total/count return mean

Call: myMean([2.5, 3.5, 4.0]) returns 3.33.

  1. How does the flow of execution change when a function is called in Python? Illustrate.
    Answer: When a function is called, control jumps to its definition, executes statements, then returns to the caller.
    Example:

python
print("Start") def hello(): print("Hi") hello() print("End")

Order: "Start", "Hi", "End".

  1. What are parameters and arguments? Differentiate with example.
    Answer: Parameters are variables in function headers; arguments are actual values supplied in calls.
    Example:

python
def greet(name): print("Hello", name) greet("Ali")
  1. Create a function that calculates both area and perimeter of a rectangle and returns both.
    Answer:

python
def rect(l, w): area = l * w peri = 2*(l + w) return area, peri

Calling rect(3,4) returns (12, 14).

  1. Demonstrate with code how default parameters work in Python functions.
    Answer:

python
def greet(name, msg="Hello"): print(msg, name) greet("Ali") # Prints: Hello Ali greet("Ali", "Welcome") # Prints: Welcome Ali
  1. Describe local and global variables with example. What is the outcome if names are reused?
    Answer:
    Global: Defined outside any function. Local: within a function.

python
x = 10 def func(): x = 5 print(x) func() # prints 5 print(x) # prints 10

Local x does not affect global x.

  1. Write a function to compute and return factorial of a number.
    Answer:

python
def calcFact(n): fact = 1 for i in range(n, 0, -1): fact *= i return fact

For n = 5, returns 120.

  1. Explain the use of return statement in a function with an example.
    Answer: The return sends a value back to the caller, and ends function execution.
    Example:

python
def square(n): return n*n

Calling square(5) returns 25.

  1. List three advantages of using functions in programming.
    Answer:

  2. Improves code readability

  3. Enables code reuse

  4. Simplifies testing and debugging

  5. Write a function that swaps two numbers if the first is less than the second, else keeps order.
    Answer:

python
def swap(a, b): if a < b: return b, a else: return a, b
  1. Describe the role of Python standard library modules with examples.
    Answer: Standard libraries provide ready-made functions, e.g., math.sqrt(16) returns 4; random.randint(1,5) returns a random int between 1 and 5.

  2. Write a function to return quotient and remainder for given two numbers.
    Answer:

python
def division(a, b): if b != 0: return a // b, a % b else: return None, None
  1. With code, differentiate between built-in and user-defined functions.
    Answer:
    Built-in: print(), sum() available in Python. User-defined:

python
def add(x, y): return x + y
  1. Explain the concept and use of docstrings in modules/functions.
    Answer: Docstrings document a function/module. Example:

python
def add(x, y): """Returns the sum of x and y""" return x + y

Accessed by print(add.__doc__)

  1. Create a function for simple authentication and display proper messages.
    Answer:

python
def login(uid, pwd): if uid == "ADMIN" and pwd == "St0rE1": return "Login successful" else: return "Access denied"
  1. Write a program for compound interest calculation using a function.
    Answer:

python
def comp_int(P, R, T, N): CI = P*(1 + R/N)**(N*T) return CI

comp_int(1000, 0.05, 2, 1) returns final amount.

  1. Show how to import only specific functions from a module. Give example.
    Answer:
    Syntax: from math import sqrt, ceil
    Now use: sqrt(25), ceil(4.2) directly.

  2. Write a function to simulate a traffic light. Explain its use.
    Answer:

python
def traffic_light(signal): if signal == "RED": return "STOP" elif signal == "YELLOW": return "WAIT" elif signal == "GREEN": return "GO" else: return "Invalid signal"

Used for safety control and decision making.

  1. Explain how a function can be designed to handle and display mixed fractions. Give code.
    Answer:

python
def mixedFraction(num, deno=1): if num % deno != 0: quotient = num // deno remainder = num % deno print(f"Mixed Fraction: {quotient} {remainder}/{deno}") else: print("Whole Number") mixedFraction(17, 2) # Output: Mixed Fraction: 8 1/2

3 marks questions with detailed answers

  1. Explain with example the concept of modular programming.
    Answer: Modular programming divides code into independent blocks called functions. Example:

python
def add(x, y): return x + y def subtract(x, y): return x - y

In a program, these functions can be reused and called as needed, improving organization and reusability.

  1. Write a user-defined function to find the mean of a list of values.
    Answer:

python
def myMean(myList): total = sum(myList) count = len(myList) mean = total/count return mean

Call: myMean([2.5, 3.5, 4.0]) returns 3.33.

  1. How does the flow of execution change when a function is called in Python? Illustrate.
    Answer: When a function is called, control jumps to its definition, executes statements, then returns to the caller.
    Example:

python
print("Start") def hello(): print("Hi") hello() print("End")

Order: "Start", "Hi", "End".

  1. What are parameters and arguments? Differentiate with example.
    Answer: Parameters are variables in function headers; arguments are actual values supplied in calls.
    Example:

python
def greet(name): print("Hello", name) greet("Ali")
  1. Create a function that calculates both area and perimeter of a rectangle and returns both.
    Answer:

python
def rect(l, w): area = l * w peri = 2*(l + w) return area, peri

Calling rect(3,4) returns (12, 14).

  1. Demonstrate with code how default parameters work in Python functions.
    Answer:

python
def greet(name, msg="Hello"): print(msg, name) greet("Ali") # Prints: Hello Ali greet("Ali", "Welcome") # Prints: Welcome Ali
  1. Describe local and global variables with example. What is the outcome if names are reused?
    Answer:
    Global: Defined outside any function. Local: within a function.

python
x = 10 def func(): x = 5 print(x) func() # prints 5 print(x) # prints 10

Local x does not affect global x.

  1. Write a function to compute and return factorial of a number.
    Answer:

python
def calcFact(n): fact = 1 for i in range(n, 0, -1): fact *= i return fact

For n = 5, returns 120.

  1. Explain the use of return statement in a function with an example.
    Answer: The return sends a value back to the caller, and ends function execution.
    Example:

python
def square(n): return n*n

Calling square(5) returns 25.

  1. List three advantages of using functions in programming.
    Answer:

  2. Improves code readability

  3. Enables code reuse

  4. Simplifies testing and debugging

  5. Write a function that swaps two numbers if the first is less than the second, else keeps order.
    Answer:

python
def swap(a, b): if a < b: return b, a else: return a, b
  1. Describe the role of Python standard library modules with examples.
    Answer: Standard libraries provide ready-made functions, e.g., math.sqrt(16) returns 4; random.randint(1,5) returns a random int between 1 and 5.

  2. Write a function to return quotient and remainder for given two numbers.
    Answer:

python
def division(a, b): if b != 0: return a // b, a % b else: return None, None
  1. With code, differentiate between built-in and user-defined functions.
    Answer:
    Built-in: print(), sum() available in Python. User-defined:

python
def add(x, y): return x + y
  1. Explain the concept and use of docstrings in modules/functions.
    Answer: Docstrings document a function/module. Example:

python
def add(x, y): """Returns the sum of x and y""" return x + y

Accessed by print(add.__doc__)

  1. Create a function for simple authentication and display proper messages.
    Answer:

python
def login(uid, pwd): if uid == "ADMIN" and pwd == "St0rE1": return "Login successful" else: return "Access denied"
  1. Write a program for compound interest calculation using a function.
    Answer:

python
def comp_int(P, R, T, N): CI = P*(1 + R/N)**(N*T) return CI

comp_int(1000, 0.05, 2, 1) returns final amount.

  1. Show how to import only specific functions from a module. Give example.
    Answer:
    Syntax: from math import sqrt, ceil
    Now use: sqrt(25), ceil(4.2) directly.

  2. Write a function to simulate a traffic light. Explain its use.
    Answer:

python
def traffic_light(signal): if signal == "RED": return "STOP" elif signal == "YELLOW": return "WAIT" elif signal == "GREEN": return "GO" else: return "Invalid signal"

Used for safety control and decision making.

  1. Explain how a function can be designed to handle and display mixed fractions. Give code.
    Answer:

python
def mixedFraction(num, deno=1): if num % deno != 0: quotient = num // deno remainder = num % deno print(f"Mixed Fraction: {quotient} {remainder}/{deno}") else: print("Whole Number") mixedFraction(17, 2) # Output: Mixed Fraction: 8 1/2

5 marks questions with detailed answers

  1. Discuss modular programming and demonstrate how functions make programs organized and reusable.
    Answer:
    Modular programming divides a large program into independent blocks, each performing a specific task called a function. This approach makes code more organized, readable, and maintainable. For example, in a tent manufacturing program, separate functions can calculate canvas area, cost, and tax. These can be reused for new products, reducing effort and errors.

  2. Write a Python program using user-defined functions to calculate the area and cost of making a tent as described in the text.
    Answer:

python
def cyl_area(h, r): return 2*3.14*r*h def con_area(r, l): return 3.14*r*l def post_tax(cost): return cost + 0.18*cost h = float(input("Cyl height: ")) r = float(input("Radius: ")) l = float(input("Slant height: ")) canvas_area = cyl_area(h,r) + con_area(r,l) unit_price = float(input("Unit price: ")) total_cost = unit_price * canvas_area net_payable = post_tax(total_cost) print("Total area:", canvas_area) print("Total cost:", total_cost) print("Net payable:", net_payable)

This breaks the problem into logical functions, each handling one part.

  1. Explain with code how arguments and parameters work in Python functions, including passing and receiving values.
    Answer:
    Arguments are values passed to functions during calls; parameters are variables receiving these values.

python
def sum_of_n(n): total = 0 for i in range(1,n+1): total += i return total num = int(input("n: ")) print(sum_of_n(num)) # argument num assigned to parameter n

Shows both passing, receiving, and using arguments.

  1. Describe how default parameters work. Give an example where the default is used and where it is overwritten.
    Answer:
    Default parameters allow functions to have preset values.

python
def power(base, exp=2): return base**exp print(power(3)) # Uses default exp=2 → 9 print(power(3,4)) # Overwrites default → 81

First call omits exp, so default 2 is used; second provides exp=4.

  1. Explain the difference between local and global variable scope in functions, with detailed code illustrations.
    Answer:
    Global variables are defined outside functions and accessible throughout; local exist within functions only.

python
x = 10 def test(): x = 5 print("local:", x) test() # prints 5 print("global:", x) # prints 10 def mod_global(): global x x = 15 mod_global() print("changed global:", x) # prints 15

Local x doesn't affect global x unless specified with "global".

  1. Design a menu-driven calculator using functions for basic arithmetic and trigonometric operations.
    Answer:

python
import math def add(a, b): return a + b def sub(a, b): return a - b def mul(a, b): return a * b def div(a, b): return a / b if b != 0 else "Error" def trig(x, op): if op=='sin': return math.sin(x) elif op=='cos': return math.cos(x) elif op=='log': return math.log10(x) while True: choice = input("Choose op (+,-,*,/,sin,cos,log,exit): ") if choice == 'exit': break if choice in ('sin','cos','log'): x = float(input("Value: ")) print(trig(x, choice)) else: a = float(input("a: ")) b = float(input("b: ")) if choice=='+': print(add(a,b)) elif choice=='-': print(sub(a,b)) elif choice=='*': print(mul(a,b)) elif choice=='/': print(div(a,b))
  1. Describe how to use docstrings in functions and modules. Write sample code and show how to display the docstring.
    Answer:
    Docstrings are the first line in a function/module, inside triple quotes, explaining its purpose.

python
def rectangle_area(l, w): """Calculates area of rectangle""" return l * w print(rectangle_area.__doc__)

Prints: "Calculates area of rectangle"

  1. Write a Python module named basicmath with four arithmetic operations and show how to import and use it.
    Answer:
    Module basicmath.py:

python
"""Basic Math Operations Module""" def add(x, y): return x + y def sub(x, y): return x - y def mul(x, y): return x * y def div(x, y): return x / y if y != 0 else "Division by Zero Error"

Import and use:

python
import basicmath print(basicmath.add(5,2)) print(basicmath.div(5,0))

Also, display docstring: print(basicmath.__doc__)

  1. Explain built-in vs user-defined functions with code and use-cases.
    Answer:
    Built-in functions (input, sum, print) are provided by Python; user-defined are created by the programmer.
    Built-in:

python
a = int(input("Enter value: ")) print(abs(a))

User-defined:

python
def cube(n): return n*n*n print(cube(5))

Built-ins are for common tasks, user-defined for specific needs.

  1. Write a function that simulates a traffic light, returning different messages based on light color input.
    Answer:

python
def traffic_light(color): if color == "RED": return "STOP, your life is precious." elif color == "YELLOW": return "WAIT, till it's green." elif color == "GREEN": return "GO! Thank you for being patient." else: return "Invalid color" signal = input("Enter color: ").upper() print(traffic_light(signal)) print("SPEED THRILLS BUT KILLS")
  1. Write a function to determine if a student has short attendance given working days and absences. Explain logic and output.
    Answer:

python
def short_attendance(total_days, days_present): attendance_perc = (days_present/total_days)*100 return 1 if attendance_perc < 78 else 0 # 1 means short, 0 means sufficient attendance

Function calculates attendance percentage, returns 1 if below 78%.

  1. Create a GK quiz function set with scoring and remarks; display final score and feedback.
    Answer:

python
def score(ans_list, correct_list): return sum([a==b for a,b in zip(ans_list, correct_list)]) def remark(score_val): marks = {5:"Good",4:"Outstanding",3:"Excellent",2:"Read more",1:"Needs interest",0:"Take it seriously"} print(marks.get(score_val, "Invalid")) correct = ['A','B','A','C','D'] user_ans = ['A','B','A','B','D'] s = score(user_ans, correct) remark(s)

Displays remark based on score.

  1. Write a function to swap two numbers only if the first is less than the second. Explain with sample input and output.
    Answer:

python
def conditional_swap(a, b): if a < b: return b, a else: return a, b # Example: conditional_swap(2,5) returns (5,2)
  1. Write a program using functions to display the first n Fibonacci numbers. Explain your solution.
    Answer:

python
def fibonacci(n): a, b = 1, 1 print(a, b, end=' ') for i in range(n-2): a, b = b, a+b print(b, end=' ') fibonacci(10)

Starts with 1, 1 and prints next n-2 terms by summing last two.

  1. Design a function-based menu system to calculate area/perimeter for multiple shapes, using function import.
    Answer:
    Module shapes.py:

python
def area_square(a): return a*a def area_rect(l,w): return l*w def area_circle(r): return 3.14*r*r def peri_rect(l,w): return 2*(l+w) def peri_circle(r): return 2*3.14*r

Import and use:

python
from shapes import area_square, peri_circle print(area_square(5)) print(peri_circle(7))
  1. Explain the concept of returning multiple values from a function with code and real-life application.
    Answer:
    Python can return multiple values as a tuple.

python
def stats(l): return min(l), max(l), sum(l)/len(l) result = stats([2,4,7]) print("Min:", result[0], "Max:", result[1], "Mean:", result[2])
  1. Design a login function to block account after three failed attempts; show logic and typical output.
    Answer:

python
def login(uid, pwd): attempts = 0 while attempts < 3: if uid == "ADMIN" and pwd == "St0rE1": print("Login successful") return True else: attempts += 1 if attempts == 3: print("Account blocked") return False uid = input("User ID: ") pwd = input("Password: ")

Prompts for credentials, blocks account after 3 failures.

  1. Tell how functions increase team collaboration and parallel work, giving practical examples.
    Answer:
    Functions divide large tasks between team members; each person writes functions independently for assigned features (billing, reporting, calculations), then integrates into the main program, speeding up development and reducing conflicts.

  2. Describe the flow of execution in a function-based Python program, highlighting function calls and returns.
    Answer:
    Interpreter reads each line; on encountering a function call, jumps to function, executes code, returns result, resumes main code. Order is influenced by call hierarchy; for recursion, functions call themselves until base case met.

  3. Explain the composition of functions in Python, showing dependency and nested calls with examples.
    Answer:
    Function composition is calling one function from another, passing outputs as input.

python
def square(x): return x*x def cube(x): return x*square(x) print(cube(3)) # cube calls square(3)

PREVIOUS CHAPTER QUESTION BANK CLICK BELOW

CHAPTER 1 

CHAPTER 2

CHAPTER 3

CHAPTER 4

CHAPTER 5 

CHAPTER 6 

[NOTE: Kindly cross check answers once from other source also, Quantity and Quality of answers also kindly check before use, specially 5 marks answers are not sufficient kindly add from your side, this gives just quick review]


Comments