| def digits(n): | |
| """Given a positive integer n, return the product of the odd digits. | |
| Return 0 if all digits are even. | |
| For example: | |
| digits(1) == 1 | |
| digits(4) == 0 | |
| digits(235) == 15 | |
| """ | |
| product = 1 | |
| odd_count = 0 | |
| for digit in str(n): | |
| int_digit = int(digit) | |
| if int_digit%2 == 1: | |
| product= product*int_digit | |
| odd_count+=1 | |
| if odd_count ==0: | |
| return 0 | |
| else: | |
| return product | |