Functions – NCERT Class 11 Computer Science Chapter 7 – Defining, Calling, and Understanding Functions in Python
Introduces the concept of functions as modular blocks of code that perform specified tasks. Covers function definition, function calling, parameters, return statements, and the advantages of using functions like code reusability and improved readability. Explains built-in functions and user-defined functions with examples in Python programming.
Tags: Functions, Python Functions, Function Definition, Function Call, Parameters, Return Statement, Built-in Functions, User-defined Functions, Modularity, Code Reusability, NCERT Class 11, Computer Science, Chapter 7
Functions: NCERT Class 11 Chapter 7 - Enhanced Study Guide, Precise Notes, Diagrams & Quiz 2025
Functions
Chapter 7: Enhanced NCERT Class 11 Guide | Expanded Precise Notes from Full PDF, Detailed Explanations, Diagrams, Examples & Quiz 2025
Enhanced Full Chapter Summary & Precise Notes from NCERT PDF (32 Pages)
Overview & Key Concepts
Exact Definition: "Function can be defined as a named group of instructions that accomplish a specific task when it is invoked."
Introduction: Modular programming for complex problems (tent example: Programs 7-1 without functions vs 7-2 with); Benefits: Readability, reusability. Quote: R. Tarjan on algorithms.
2025 Relevance: Functions in ML pipelines (e.g., scikit-learn); Modular code in microservices; Reusability for APIs.
7.1 Introduction
Precise: As programs grow bulky, modular approach divides into blocks (Fig 7.2). Tent: Accept inputs, calc areas/cost/tax (Prog 7-1 vs 7-2).
7.2 Functions
Precise: Named instructions for tasks; Invoked by name; Reusable. Expanded: Achieves modularity; Prog 7-2 reuses con(l,r) for new tents.
Precise Fig 7.2: Modular Calculation (SVG)
7.2.1 Advantages
Precise: Readability, reduces length/debugging, reusability, team division. Expanded: Reuse post_tax_price(18%) across services.
7.3 User Defined Functions
Precise: Custom def for tasks; Syntax: def func([params]): body [return]. Expanded: Optional params/return; Call by name().
Program 7-3: addnum() Example
# Program 7-3
def addnum():
fnum = int(input("Enter first number: "))
snum = int(input("Enter second number: "))
sum = fnum + snum
print("The sum of ",fnum,"and ",snum,"is ",sum)
addnum()
Output: Enter first number: 5 Enter second number: 6 The sum of 5 and 6 is 11
7.3.2 Arguments and Parameters
Precise: Args passed to params; Same value/ID initially (Fig 7.3); Changes may reassign (Prog 7-5). Strings as params (Prog 7-8).
Precise Fig 7.3: Argument/Parameter Binding (SVG)
Program 7-4: sumSquares(n)
# Program 7-4
def sumSquares(n):
sum = 0
for i in range(1,n+1):
sum = sum + i
print("The sum of first",n,"natural numbers is: ",sum)
num = int(input("Enter the value for n: "))
sumSquares(num)
Output (n=5): The sum of first 5 natural numbers is: 15
Scope of Variables
Precise: Local (inside func), Global (outside); Use global keyword. Expanded: Avoid name clashes.
7.5 Python Standard Library
Precise: Pre-built functions (e.g., math.sqrt); Import modules. Expanded: math, random for reusability.
Enhanced Features (2025)
Full PDF integration, expanded programs (7-1 to 7-8), SVGs (Figs 7.1-7.4), detailed tables/examples, 30 Q&A updated, 10-Q quiz. Focus: Modular Python coding.
Exam Tips
Write functions (area/sum/factorial); Explain args/params with ID; Advantages list; Syntax diagram; Scope examples; Standard lib import.
User Defined Functions - Syntax & Examples Expanded
Core: def for custom tasks; Optional params/return.
Example: Prog 7-3 (no params), 7-7 (calcFact(num)).
UDF Syntax (SVG)
Examples:
Program 7-7: calcFact(num)
# Program 7-7
def calcFact(num):
fact = 1
for i in range(num,0,-1):
fact = fact * i
print("Factorial of",num,"is",fact)
num = int(input("Enter the number: "))
calcFact(num)
Output: Enter the number: 5 Factorial of 5 is 120
Tip: 2025: Lambda for anonymous funcs in data pipelines.
Arguments & Parameters - Binding & ID Changes Expanded
Core: Pass values; Params receive; ID same initially (Fig 7.4).
7.3.2 Args/Params (Detailed)
Explanation: Arg at call → Param in header; Rebind on change (Prog 7-5).
Example: Prog 7-6 (myMean(list)), 7-8 (strings).
Fig 7.4: ID Before/After Increment (SVG)
Program 7-8: Full Name Concat
# Program 7-8
def displayFullName(first, last):
full = first + " " + last
print("Hello", full)
first = input("First name: ")
last = input("Last name: ")
displayFullName(first, last)
Output: First name: Gyan Last name: Vardhan Hello Gyan Vardhan
Tip: 2025: *args/**kwargs for variable args in APIs.
Advantages of Functions & Scope - Expanded
Core: Readability/reusability; Local/global vars.
7.2.1 Advantages (Detailed)
List: Organized code, less repetition, reusable, parallel work.
Example: Reuse con(l,r) for rectangular base tents.
Scope (Detailed)
Explanation: Local: Func body; Global: Module-wide; global keyword for access.
Example: Var in func not visible outside.
Scope Diagram (SVG)
Tip: 2025: Namespaces in cloud functions (AWS Lambda).
Ans: Named reusable code; Invoke by name. Adv: Organized/readable; Short/debug easy; Reusable (call multiple); Team divide. E.g., Reuse for rectangular tents. Essential for large code.
Ans: Pass at call; Receive in header (Fig 7.3). Same ID init (Prog 7-5: 1712903328); Reassign on op (new ID). Strings: Concat (7-8). Binding like pass-by-object-ref.
Q25: Explain scope with example.
Ans: Local: Func vars; Global: Outside. global x to modify global. Example: def f(): x=5 (local); x=10 outside (global). Clashes avoided; nonlocal for nested.
Q26: Programs for numeric/string funcs.
Ans: Numeric: 7-5 incrValue (ID change); 7-7 fact (loop). String: 7-8 full name (+ space). Outputs: 13 new ID; Hello Gyan Vardhan. Reusable blocks.
Q27: Advantages in team/program dev.
Ans: Parallel: One func per member. Reusability: Build on existing. Less rep: No copy-paste. Debug: Isolate issues. 2025: CI/CD with modular tests.
Q28: Standard library vs UDF.
Ans: Std: Pre-built (import math); UDF: Custom def. Use std for common (sqrt); UDF for specific (tent area). Both reusable; Std saves time.
Q29: How functions achieve modularity?
Ans: Independent blocks/sub-problems. Tent: Separate cyl/con/tax funcs. Easier manage/complex. From inline (7-1) to modular (7-2). Scalable design.
Q30: Apply chapter to real program.
Ans: Tent calc: Inputs funcs, area funcs, cost/tax funcs. Reusable for variants. Scope: Local vars. Std: Use pi from math. Builds efficient code. 2025: Funcs in serverless.
Tip: Include programs/ID examples; Practice def/call.
Quick Revision Notes & Enhanced Mnemonics
Functions
def name(): body; return opt.
Mnemonic: "DRB" (Define Return Body).
Args/Params
Pass at call; Receive in header.
Mnemonic: "AP" (Arg Passed).
Advantages
Read/Reuse/Debug/Team.
Mnemonic: "RRD Team".
Scope
Local/Global; global keyword.
Mnemonic: "LG Global".
Std Library
Import modules; Pre-built.
Mnemonic: "IP" (Import Pre).
Modular
Blocks for sub-problems.
Mnemonic: "MB Sub".
Overall: "Intro Func UDF Args Scope Std" (I F U A S S). Flashcards ready.
Interactive Quiz: 10 Updated Questions from Full Chapter