Question: Code the following in Python 2.x. is_superadditive_prime() in primes.py : Superadditive primes [15 points] We will call a positive integer superadditive prime 1 if and

 Code the following in Python 2.x. is_superadditive_prime() in primes.py: Superadditive primes Code the following in Python 2.x. is_superadditive_prime() in primes.py: Superadditive primes [15 points] We will call a positive integer superadditive prime1 if and only if it is prime and either (i) single-digit, or (ii) the sum of its digits is also a superadditive prime. For example, 1787 is super-additive because 1787 itself is prime, and the sum of its digits 1 + 7 + 8 + 7 = 23 is also prime, and the sum of its digits 2 + 3 = 5 is also prime and single-digit. However, 1783 is not superadditive, because even though 1783 is prime and 1 + 7 + 8 + 3 = 19 is also prime, the sum of its digits 1 + 9 = 8 is not prime. Note that the logic of the definition is not limited to just three iterations of sum of digits; the iteration should stop after however many operations are necessary to reach a single-digit number.

Write a function is_superadditive_prime() that takes a positive integer n as argument and returns True if n is a superadditive prime, and False otherwise.

For full credit, you have to reuse the sum_digits() function that you developed previously (by importing it from digits.py). Pictured above

Please post a screenshot of your code so I can indent properly. Thanks!

bed malh.py ef sum digits(n): $python3 main.py total 0 while n>: total total + n % 10 n int (n /10 return total print (sum_digits(153)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!