📘 Quick Theory Recap
🔹 What is a Function?
A function is a block of code that performs a specific task. It can be reused multiple times.
🔹 Types of Functions:
Built-in functions – Already provided by Python (e.g., len(), sum())
User-defined functions – Created by the user using the def keyword
🔹 Syntax of a Function:
python
CopyEdit
def function_name(parameters):
# Function body
return value
🧠 Examples
Example 1: Function with no parameters and no return
python
CopyEdit
def greet():
print("Hello, students!")
Example 2: Function with parameters and return value
python
CopyEdit
def add(a, b):
return a + b
Example 3: Calling the function
python
CopyEdit
greet()
result = add(10, 5)
print(result) # Output: 15
✏️Exercises
🔸 Section A: Objective Questions
Q1. Fill in the blanks:
1. A function is defined using the ________ keyword.
2. The ________ keyword is used to return a value from a function.
3. Functions promote code ________ and reusability.
Q2. State True or False:
1. You can define multiple functions with the same name in Python.
2. A function can return only one value.
3. The function body is defined by indentation.
🔸 Section B: Short Answer Questions
Q3. What is the difference between built-in and user-defined functions?
Q4. What will be the output of the following code?
python
CopyEdit
def square(x):
return x * x
print(square(3))
print(square(5))
Q5. Identify the error in this code:
python
CopyEdit
def greet(name)
print("Hi", name)
🔸 Section C: Write the Code
Q6. Write a function named multiply that takes two arguments and returns their product.
Q7. Write a function called is_even that returns True if a number is even, otherwise False.
Q8. Define a function that accepts a string and prints it in uppercase.
🔸 Section D: Higher Order Thinking Skills (HOTS)
Q9. Write a function fibonacci(n) that prints the first n terms of the Fibonacci sequence.
Q10. Write a function that counts and returns the number of vowels in a given string.
📎 Teacher’s Note / Tips for Students
Use meaningful function names and comments to improve code readability.
Practice tracing functions step-by-step to understand flow.
Try creating small functions to solve real-life problems like calculators or temperature
converters.
Would you like:
✅ An Answer Key?
📄 A PDF or DOCX version?
🧪 A worksheet with MCQs or coding-based assessments?
Let me know and I’ll generate the format you need!
You said:
answer key
ChatGPT said:
Great! Here's the Answer Key for the Class 12 Python Functions Worksheet.
✅ Answer Key – Class 12 Python
Worksheet: Functions
🔸 Section A: Objective Questions
Q1. Fill in the blanks:
1. def
2. return
3. modularity
Q2. True or False:
1. False – You cannot have multiple functions with the same name in the same scope.
2. False – A function can return multiple values using tuples.
3. True – Indentation is used to define blocks of code, including the function body.
🔸 Section B: Short Answer Questions
Q3. Difference between built-in and user-defined functions:
Built-in Functions User-defined Functions
Provided by Python by default Created by the programmer
Example: len(), max() Example: def greet():
Can be used directly Must be defined before use
Q4. Output:
python
CopyEdit
def square(x):
return x * x
print(square(3)) # 9
print(square(5)) # 25
Answer:
CopyEdit
9
25
Q5. Identify the error:
python
CopyEdit
def greet(name)
print("Hi", name)
Corrected Version:
python
CopyEdit
def greet(name):
print("Hi", name)
Error: Missing colon : at the end of the function definition line.
🔸 Section C: Write the Code
Q6. Multiply Function:
python
CopyEdit
def multiply(a, b):
return a * b
Q7. Even Checker Function:
python
CopyEdit
def is_even(n):
return n % 2 == 0
Q8. Uppercase Printer:
python
CopyEdit
def print_upper(text):
print(text.upper())
🔸 Section D: Higher Order Thinking Skills (HOTS)
Q9. Fibonacci Function:
python
CopyEdit
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
Q10. Vowel Counter Function:
python
CopyEdit
def count_vowels(text):
vowels = "aeiouAEIOU"
count = 0
for char in text:
if char in vowels:
count += 1
return count