Page 282 - CTS - CSA TP - Volume 2
P. 282
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 129 : Write a python program depicting argument
passing and using tuples, dictionaries as
arguments
Objectives
At the end of this exercise you shall be able to
• develop python program to argument passing and using tuples, dictionaries as arguments.
Procedure
TASK 1: Using Tuple
defcalculate_average(*numbers):
“””
This function takes variable positional arguments (numbers) as a tuple
and calculates their average.
Args:
*numbers: Variable positional arguments (packed into a tuple).
Returns:
float: Average of the numbers.
“””
ifnot numbers:
return0 # Avoid division by zero
average = sum(numbers) / len(numbers)
return average
# Example usage:
result = calculate_average(10,20,30,40,50)
num=(10,20,30,40,50)
print(“Numbers in Tuple are: “,num)
print(“Average:”, result)
Output:
267