Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in Python with the following: a) Function isPrime : - descriptio

ID: 3808343 • Letter: W

Question

Write a program in Python with the following:

a) Function isPrime:

- description: verifies if a whole number is prime.

- input parameter: whole number.

- return: True or False.

Remark: a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

b) Function isOdd:

- description: verifies if a whole number is odd.

- input parameter: whole number.

- return: True of False

c) Function power:

- description: calculates the exponentiation of a whole number.

- input parameters: whole number, exponent

- return: number to the power of exponent.

c) Function main:

- description: using functions isPrime, isOdd and power, show the odd prime numbers between the numbers from 1 to 100 (inclusive), and the corresponding exponentiation values: n0, n1, n2 and n3, in a table like the following:

------------------------------------------------------------------

Odd Prime    Power of    Power of Power of Power of

      Number                0                1               2               3

------------------------------------------------------------------

                  3                1                3               9             27

                  5                1                5             25           125

                11                1              11           121         1331

                79                1              79         6241     493039

                83                1              83         6889     571787

                89                1              89         7921     704969

                97                1              97         9409     912673

------------------------------------------------------------------

Show the results on the screen.

For the coding, use:

- camel or Hungarian notation

- in-program comments

- logic

- accuracy

- efficiency

Remark: you can't use any Math built-in function.

Explanation / Answer

[1]
import math

def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0 or n <= 1:
        return False

        sqr = int(math.sqrt(n)) + 1

    for div in range(3, sqr, 2):
        if n % div == 0:
            return False
    return True

[2]

def isOdd(n):
    if (n%2) == 0:
        return False
    else:
        return True
  
[3]

def power(n,p):
     return n**p
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote