-1

I'm trying to write a method that returns the product of prime digits in a number.

I got stuck after the for loop. I don't know how to multiply all the prime numbers. any help?

An example of the function: The number 124563 has three prime digits: 2, 5, 3, and the product of these three numbers is 30. So my method should return 30 when supplied with 124563.

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
Amitco666
  • 15
  • 2
  • 1
    Welcome to Stack Overflow! Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly as a [mre]. You can get more [formatting help here](https://stackoverflow.com/help/formatting). You can also read about [why you shouldn't post images/links of code](//meta.stackoverflow.com/q/285551). – Tomerikoo Nov 01 '21 at 20:48
  • 1
    [idownvotedbecau.se/imageofcode](https://idownvotedbecau.se/imageofcode). Add each number which is prime, to a list (`append`) and then calculate the product. Your code doesn't even have a prime number check or a prime number list. – aneroid Nov 01 '21 at 20:48
  • 2
    Your question is a multi-duplicate that can be answered by following this: First [Iterate over digits of number](https://stackoverflow.com/q/28268196/6045800), then [Checking if a number is a prime number in Python (duplicate)](https://stackoverflow.com/q/4114167/6045800) and add it to a list. Then, [How can I multiply all items in a list together with Python?](https://stackoverflow.com/q/13840379/6045800) – Tomerikoo Nov 01 '21 at 20:51

1 Answers1

0

See if this helps:

def productPrime(num):

    result = 1
    
    prime_numbers = [2,3,5,7] ## since you want to multiply only prime digits otherwise you need to write a code to check prime number
    
    while num > 0:
        if (num % 10) in prime_numbers:
            result = result*(num % 10)
        num = num//10
        
    if result != 1:
        return result
    else:
        return ("No prime digit in number")