Write a function primeFac in Python that computes the prime factorization of a number:
- it accepts a single argument, an integer greater than 1
- it returns a list containing the prime factorization
each number in the list is a prime number greater than 1
the product of the numbers in the list is the original number
the factors are listed in non-decreasing order
Examples of possibles results:
>>> primeFac(5)
[5]
>>> primeFac(72)
[2, 2, 2, 3, 3]
>>> primeFac(72)==[2, 2, 2, 3, 3]
True
>>> [ (i,primeFac(i)) for i in range(10,300,23)]
[(10, [2, 5]), (33, [3, 11]), (56, [2, 2, 2, 7]), (79, [79]), (102, [2, 3, 17]),
(125, [5, 5, 5]), (148, [2, 2, 37]), (171, [3, 3, 19]), (194, [2, 97]), (217,
[7, 31]), (240, [2, 2, 2, 2, 3, 5]), (263, [263]), (286, [2, 11, 13])]
>>> [ (i,primeFac(i)) for i in range(3,300,31)]
[(3, [3]), (34, [2, 17]), (65, [5, 13]), (96, [2, 2, 2, 2, 2, 3]), (127, [127]),
(158, [2, 79]), (189, [3, 3, 3, 7]), (220, [2, 2, 5, 11]), (251, [251]), (282,
[2, 3, 47])]
Please only give to me the final code or the "tool" that could generate any of the above results. Thanks!
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Sol in python apply list and tuples and write commentsarrow_forwardplease code in python The following code defines a list of names and also contains a header for the function best. The best function takes two arguments: a generic scoring function, score, and a list of strings, names. Fill in the function so that it applies a score function to each string in the names list and returns the name with the highest score. If there are ties in the list, your function should return the first item with the maximum score. The best function needs to be designed so that it can take any scoring function and return the name with the highest score. For this question, define a function called len_score that returns the length of a word. Call the best function with the len_score function as a parameter. Example: names = ["Ben", "April", "Zaber", "Alexis", "McJagger", "J.J.", "Madonna"] best(len_score, names) -> 'McJagger'arrow_forwardC Programming Language Note: Input and Output Must be the same Write in C Languagearrow_forward
- Problem DNA: Subsequence markingA common task in dealing with DNA sequences is searching for particular substrings within longer DNA sequences. Write a function mark_dna that takes as parameters a DNA sequence to search, and a shorter target sequence to find within the longer sequence. Have this function return a new altered sequence that is the original sequence with all non-overlapping occurrences of the target surrounded with the characters >> and <<. Hints: ● String slicing is useful for looking at multiple characters at once. ● Remember that you cannot modify the original string directly, you’ll need to build a copy. Start with an empty string and concatenate onto it as you loop. Constraints: ● Don't use the built-in replace string method. All other string methods are permitted. >>> mark_dna('atgcgctagcatg', 'gcg') 'at>>gcg<<ctagcatg' >>> mark_dna('atgcgctagcatg', 'gc')…arrow_forwardPYTHON Problem Statement Given a list of numbers (nums), for each element in nums, calculate how many numbers in the list are smaller than it. Write a function that does the calculation and returns the result (as a list). For example, if you are given [6,5,4,8], your function should return [2, 1, 0, 3] because there are two numbers less than 6, one number less than 5, zero numbers less than 4, and three numbers less than 8. Sample Input smaller_than_current([6,5,4,8]) Sample Output [2, 1, 0, 3]arrow_forwardC++ The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version of the binary search algorithm. The program should prompt Y / y to continue searching and N / n to discontinue. If an item is found in the list display the following message: x found at position y else: x is not in the list Use the following list of integers when testing your program: 2, 6, 8, 13, 25, 33, 39, 42, 53, 58, 61, 68, 71, 84, 97arrow_forward
- Python languagearrow_forwardP1: this is data structure of algorithms subject and topic is all about Stack Applicationsarrow_forwarddef find_root4(x, epsilon): ''' IN PYTHON Assume: x, epsilon are floating point numbers and epsilon > 0 Use bisection search to find the following root of x such that If x >=0, return y such that x - epsilon <= y ** 2 <= x + epsilon Else, return y such that x - epsilon <= y ** 7 <= x + epsilon Note: You must use bisection search to implement the function. ''' passarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education