Page 267 - CTS - CSA TP - Volume 2
P. 267
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• Multi-line comments are enclosed in triple double-quotes (“””).
Output:
TASK 3: Documentation String (Docstring)
Code:
defadd_numbers(a, b):
“””
This function adds two numbers.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The sum of the two numbers.
“””
result = a + b
return result
# Example usage:
sum_result = add_numbers(5, 3)
print(“Sum:”, sum_result)
Explanation:
This code defines a function add_numbers that takes two integer parameters (a andb) and returns their sum. It
includes a docstring that provides information about the function.
1 defadd_numbers(a, b)::
• The def keyword is used to define a function.
• add_numbers is the function name.
• (a, b) specifies the parameters the function takes.
2 “”” ... “””:
• The triple double-quoted string is a docstring.
• It serves as documentation for the function.
• It describes the purpose of the function, its parameters, and the return value.
3 result = a + b:
• This line calculates the sum of a and b and assigns it to the variable result.
252
CITS : IT & ITES - Computer Software Application - Exercise 127