Write a python function proddigits() that inputs a positive integer number and returns the product of digits of that number.
时间: 2024-01-03 14:04:51 浏览: 128
TCA6416A扩展芯片
Here's the Python function `proddigits()` that takes a positive integer as input and returns the product of its digits:
```python
def proddigits(num):
# Initialize product to 1
product = 1
# Convert the integer to a string to loop through its digits
num_str = str(num)
# Loop through each digit in the string
for digit in num_str:
# Multiply the digit to the current product
product *= int(digit)
# Return the final product
return product
```
You can call this function with a positive integer as an argument and it will return the product of its digits. Here's an example usage:
```python
num = 12345
product = proddigits(num)
print(product) # Output: 120
```
In this example, the input integer is 12345 and the product of its digits is 1 x 2 x 3 x 4 x 5 = 120.
阅读全文