Question

Write a python program using function prime_factorization(n) which will compute the product of all the prime...

Write a python program using function prime_factorization(n) which will compute the product of all the prime factors of a given input n.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def is_prime(n):
    if n > 1:
        for i in range(2, n):
            if (n % i) == 0:
                return False
    return n > 1


def prime_factorization(n):
    product = 1
    print("Prime factors of", n, "are:", end=' ')
    for i in range(2, n + 1):
        if is_prime(i) and n % i == 0:
            product *= i
            print(i, end=' ')
    print()
    return product


def main():
    n = int(input("Enter an integer: "))
    p = prime_factorization(n)
    print("Product of prime factors of", n, "is", p)


main()

Add a comment
Know the answer?
Add Answer to:
Write a python program using function prime_factorization(n) which will compute the product of all the prime...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and...

    write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and c) of a Quadratic equation (ax2+bx+c=0) as input and compute all possible roots b).User defined function isprime(num) that accepts an integer argument and returns 1 if the argument is prime, a 0 otherwise. Write a Python program that invokes this function to generate prime numbers between the given ranges

  • (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be...

    (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be expressed as a product of prime numbers, called its prime factorization. E.g. 15 3 x 5,20 2x 2x5. You are required to write a Python function prime factors(n) which accepts a natural number as the input argument and returns a list of all the prime factors of n in ascending order. (Use 20, 666, 4020 to test your program.) 2.

  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • In this assignment you are asked to write a Python program to determine all the prime...

    In this assignment you are asked to write a Python program to determine all the prime numbers in between a range and store them in a list that will be printed when the range is searched. The user is prompted for two positive integer values as input, one is the start of the range and the other is the end of the range. If the user gives a negative value or enters a second number that is lower than the...

  • Your program  write a program to test whether a number is prime or not. Your program should...

    Your program  write a program to test whether a number is prime or not. Your program should ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers. The program should continue to ask for input, till it sees a 0, when it exits. Please submit printed pseudocodeshould ask user to input an integer and respond: "Prime" or "Not prime". Don't use any library function that tests for prime numbers....

  • USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and...

    USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...

  • PYTHON 3 PROGRAM PLEASE 18.19* (Prime number iterator) Write an iterator class for prime numbers. Invoking...

    PYTHON 3 PROGRAM PLEASE 18.19* (Prime number iterator) Write an iterator class for prime numbers. Invoking the __next__() method returns the next prime number. Write a test program that displays all prime numbers less than 10000.

  • USING PYTHON 1. Write a small program that asks for an integer number from the user...

    USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)

  • Python homework problem First: Write a program (using a loop with break) to allow a user...

    Python homework problem First: Write a program (using a loop with break) to allow a user to input an integer and determine if the integer is prime. Then change the program to examine a number of integers to determine if each is prime. The program should allow the user to input the number of integers (say n) to be checked to determine if each is prime. Then the user should input n integers and print whether each of the integers...

  • Write a Python program that calculates the product of all odd numbers between 1 and 20...

    Write a Python program that calculates the product of all odd numbers between 1 and 20 (1x3x5x7x9x11x13x15x17x19), using the for loop and the range function.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT