Question

IN PYHTON CODE

Question #3 Produce a function prime_factors.dict that has one integer variable n that is assumed to be greater than 1. The fProgram/Source Code Here is the source code of the Python Program to find the smallest divisor of an integer The program outp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Code:

def smallest_divisor(n):

a=[]

for i in range(2, n+1):

if(n%i==0):

a.append(i)

a.sort()

return a[0]

def prime_factors_dict(n):

pf_d = {}

for i in range(2, n+1):

pf_d[i] = []

for j in range(2, i+1):

if i%j==0 and smallest_divisor(j)==j:

pf_d[i].append(j)

pf_d[i] = set(pf_d[i])

return pf_d


print(prime_factors_dict(8))

Add a comment
Know the answer?
Add Answer to:
IN PYHTON CODE Question #3 Produce a function prime_factors.dict that has one integer variable n that...
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
  • Find the smallest positive integer that has precisely n distinct prime divisors. 'Distinct prime divisor'Example: the...

    Find the smallest positive integer that has precisely n distinct prime divisors. 'Distinct prime divisor'Example: the prime factorization of 8 is 2 * 2 * 2, so it has one distinct prime divisor. Another: the prime factorization of 12 is 2 * 2 * 3, so it has two distinct prime divisors. A third: 30 = 2 * 3 * 5, which gives it three distinct prime divisors. (n = 24 ⇒ 23768741896345550770650537601358310. From this you conclude that you cannot...

  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • A perfect number is a positive integer that equals the sum of all of its divisors...

    A perfect number is a positive integer that equals the sum of all of its divisors (including the divisor 1 but excluding the number itself). For example 6, 28 and 496 are perfect numbers because 6=1+2+3 28 1 + 2 + 4 + 7 + 14 496 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 Write a program to read a positive integer value, N, and find the smallest perfect number...

  • In ASCII C programming write a function that determines if an integer is prime. A prime...

    In ASCII C programming write a function that determines if an integer is prime. A prime number is one that is not divisible by any number other than one and itself. int isPrime(long num); Return 1 if num is prime, 0 if not. As above, make this a pure function contained in its own file isPrime.c and test it with a separate tester program. To test if an integer is prime you could implement a loop that generates trial divisors...

  • MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a whi...

    MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB

  • A positive integer greater than 1 is said to be prime if it has no divisors...

    A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that defines two functions is_prime() and list_primes(). is_prime() will determine if a number is prime. list_primes() will list all the prime numbers below itself other than 1. For example, the first five prime numbers are: 2, 3, 5, 7 and 11." THE PROGRAM...

  • A Prime Number is an integer which is greater than one, and whose only factors are...

    A Prime Number is an integer which is greater than one, and whose only factors are 1 and itself. Numbers that have more than two factors are composite numbers. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. The number 1 is not a prime number. Write a well-documented, Python program - the main program, that accepts both a lower and upper integer from user entries. Construct a function, isPrime(n), that takes...

  • PYTHON 3: Write a function removeRand() that takes a dictionary d and an integer n as...

    PYTHON 3: Write a function removeRand() that takes a dictionary d and an integer n as parameters. The function randomly chooses n key-value pairs and removes them from the dictionary d. If n is greater than the number of elements in the dictionary, the function prints a message but does not make any changes to d. If n is equal to the number of elements in d, the function clears the dictionary. Otherwise the function goes through n rounds in...

  • Part 15A and 15B (15) Let n E Z+,and let d be a positive divisor of...

    Part 15A and 15B (15) Let n E Z+,and let d be a positive divisor of n. Theorem 23.7 tells us that Zn contains exactly one subgroup of order d, but not how many elements Z has of order d. We will determine that number in this exercise. (a) Determine the number of elements in Z12 of each order d. Fill in the table below to compare your answers to the number of integers between 1 and d that are...

  • Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and,...

    Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...

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
ADVERTISEMENT