Week 2 8 2nd Term Void and Return Function
Week 2 8 2nd Term Void and Return Function
Basic Level:
pythonCopy code
# Void Function (Basic)
def greet_basic(name):
print(f"Hello, {name}!")
# Example Usage
greet_basic("John")
result = add_basic(3, 5)
print("Sum:", result)
Intermediate Level:
pythonCopy code
# Void Function (Intermediate)
def print_square_intermediate(num):
square = num ** 2
print(f"The square of {num} is: {square}")
# Example Usage
print_square_intermediate(7)
numbers_list = [2, 4, 6, 8, 10]
avg = calculate_average_intermediate(numbers_list)
1|Page
print("Average:", avg)
Advanced Level:
pythonCopy code
# Void Function (Advanced)
def generate_report_advanced(data):
# Complex logic to generate a report from data
# This function may interact with databases, APIs, or perform extensive computations
print("Report Generated Successfully")
# Example Usage
data_for_report = {"user": "Alice", "transactions": [120.50, 45.30, 67.80]}
generate_report_advanced(data_for_report)
Basic Level:
pythonCopy code
# Void Function (Basic)
def greet_basic(name):
print(f"Hello, {name}!")
# Example Usage
2|Page
greet_basic("John")
result = add_basic(3, 5)
print("Sum:", result)
3. Example Usage:
o Calls greet_basic with the argument "John" to print a greeting.
o Calls add_basic with arguments 3 and 5, stores the result in the variable result,
and prints it.
Intermediate Level:
pythonCopy code
# Void Function (Intermediate)
def print_square_intermediate(num):
square = num ** 2
print(f"The square of {num} is: {square}")
# Example Usage
print_square_intermediate(7)
numbers_list = [2, 4, 6, 8, 10]
avg = calculate_average_intermediate(numbers_list)
print("Average:", avg)
3|Page
o calculate_average_intermediate is a function that takes a list of numbers and
returns their average.
o It demonstrates a function that involves more complex computation but still
follows a straightforward logic.
3. Example Usage:
o Calls print_square_intermediate with the argument 7 to print the square of 7.
o Calls calculate_average_intermediate with a list of numbers and prints the
average.
Advanced Level:
pythonCopy code
# Void Function (Advanced)
def generate_report_advanced(data):
# Complex logic to generate a report from data
# This function may interact with databases, APIs, or perform extensive computations
print("Report Generated Successfully")
# Example Usage
data_for_report = {"user": "Alice", "transactions": [120.50, 45.30, 67.80]}
generate_report_advanced(data_for_report)
4|Page
3. Example Usage:
o Calls generate_report_advanced with a sample data structure for a report.
o Calls optimize_algorithm_advanced with a list of numbers for optimization and
prints the result.
In the advanced example, the complexity of the tasks the functions perform is increased,
representing more sophisticated scenarios you might encounter in real-world applications. Keep
in mind that the exact implementation details would depend on the specific requirements of your
application.
5|Page