232k views
2 votes
1.Create a function that accepts any number of numerical (int and

float) variables as positional arguments and returns the sum ofthose variables.
2.Modify the above function to accept a keyword argument
'multiplier'. Modify the function to return an additional variable
that is the product of the sum and the multiplier.
3.Modify the above function to accept an additional keyword
argument 'divisor'. Modify the function to return an additional
variable that is the quotient of the sum and the divisor.

User Micans
by
8.3k points

1 Answer

4 votes

Answer:

This function accepts any number of numerical variables as positional arguments and returns their sum:

python

Copy code

def sum_numbers(*args):

return sum(args)

This function accepts a multiplier keyword argument and returns the product of the sum and the multiplier:

python

Copy code

def sum_numbers(*args, multiplier=1):

total_sum = sum(args)

return total_sum * multiplier

This function accepts an additional divisor keyword argument and returns the quotient of the sum and the divisor:

python

Copy code

def sum_numbers(*args, multiplier=1, divisor=1):

total_sum = sum(args)

return total_sum * multiplier, total_sum / divisor

You can call these functions with any number of numerical arguments and specify the multiplier and divisor keyword arguments as needed. Here are some examples:

python

# Example 1

print(sum_numbers(1, 2, 3)) # Output: 6

# Example 2

print(sum_numbers(1, 2, 3, multiplier=2)) # Output: 12

# Example 3

print(sum_numbers(1, 2, 3, multiplier=2, divisor=4)) # Output: (8, 3.0)

User Karantan
by
7.4k points