Page 268 - CTS - CSA TP - Volume 2
P. 268
COMPUTER SOFTWARE APPLICATION - CITS
4 return result:
• The return statement is used to return the calculated sum.
5 Example Usage:
• sum_result = add_numbers(5, 3): Calls the add_numbers function with arguments 5 and 3 and assigns the
result to sum_result.
• print(“Sum:”, sum_result): Prints the result of the addition.
This function is well-documented using a docstring, making it clear how to use it and what it does. It follows best
practices for documenting functions in Python.
Output:
TASK 4: Python for loop with range function
Code:
# Python Program to
# show range() basics
# printing a number
fori in range(10):
print(i, end=” “)
# performing sum of first 10 numbers
sum = 0
fori in range(1, 10):
sum = sum + i
print(“\nSum of first 10 numbers :”, sum)
Explanation:
The Python range() function is used to generate a sequence of numbers. Depending on how many arguments the
user is passing to the function, the user can decide where that series of numbers will begin and end as well as
how big the difference will be between one number and the next.range() takes mainly three arguments.
• start: integer starting from which the sequence of integers is to be returned
• stop: integer before which the sequence of integers is to be returned.
The range of integers ends at a stop – 1.
• step: integer value which determines the increment between each integer in the sequence.
Output:
253
CITS : IT & ITES - Computer Software Application - Exercise 127