Editor

Multiply All Arguments

Functions · Intermediate · 55 XP · about 5 min

Write a function called multiply_all(*args) that takes any number of arguments and returns their product (all multiplied together).

Example

multiply_all(2, 3)           # Returns 6
multiply_all(1, 2, 3, 4)     # Returns 24
multiply_all(5)              # Returns 5
multiply_all()               # Returns 1 (empty product)

Requirements

  • Use *args to accept any number of arguments
  • Return 1 if no arguments are provided (empty product)
  • Handle both positive and negative numbers
def multiply_all(*args):
# Your code here
pass
# Test your function
print(multiply_all(2, 3))
print(multiply_all(1, 2, 3, 4))
print(multiply_all())

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.