Code:
def multiply_list(numbers):
result = 1
for num in numbers:
result *= num
return result
# Example usage
user_input = input("Enter a list of numbers separated by spaces: ")
# Convert the input string to a list of integers
numbers_list = [int(x) for x in user_input.split()]
# Check if the list is not empty
if numbers_list:
result = multiply_list(numbers_list)
print(f"The product of the numbers in the list is: {result}")
else:
print("The list is empty.")
Output:
No comments:
Post a Comment