Question
In python 1.) divisors(n): A divisor is a number that divides something evenly. Given a positive integer n, create the list of divisors of n
In python
1.) divisors(n): A divisor is a number that divides something evenly. Given a positive integer n, create the list of divisors of n from lowest to highest. Note that 1 and n are always divisors of n. Assume: n is a positive int. Restrictions: no extra restrictions. divisors(12) [1, 2, 3, 4, 6, 12] divisors(13) [1,13] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2. has_duplicates(xs): When a sequence has two equal values anywhere in the sequence, it has a duplicate. Determine if the sequence xs has any duplicates, and return as a bool. Assume: xs is a sequence of any length (e.g., it could be a string or list). Restrictions: remember, you may not call count() or related built-in functions. has_duplicates("meter") True # two e's found has_duplicates([1,3,5,2,4]) False ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 3. truncatable_prime(n): check whether a number is a "right-truncatable prime" and return bool result. A right-truncatable prime is a prime which remains prime when the last (rightmost) digit is successively removed. (hint: how can you remove the last digit?...) o Assume: n is a positive integer. Restrictions: no extra restrictions. truncatable_prime(2) True truncatable_prime(113) False truncatable_prime(5939) True ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 4. histogram(xs): Given a list of integers named xs, return a string which, when printed, shows a histogram corresponding to the integers. Use lowercase "o" as the display symbol. Assume: xs is a list of non-negative integers; xs could be empty. Restrictions: none currently stated. histogram([3,10,0,5]) 'ooo oooooooooo ooooo ' histogram([]) '' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 5. second_smallest(xs): Given a list, xs, figure out what the second-smallest value in the list is. When there are duplicates for the smallest, like [2,4,3,2,5], the 'second copy' is the second-smallest. Assume: xs is a list of ints with at least two values in it. Restrictions: you may not call any sorting operations use loop(s) and track what you see as you navigate through the list. You may not call min() or max() style functions either use relational operators (like < ) to perform the comparisons. second_smallest( [1, 2, 3, 4, 5] ) second_smallest( [5, 1, -4, -3, 2]) second_smallest( [2, 4, 3, 2, 5] ) 2 -3 2 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 6. mode(xs): The mode of a list is the value that occurs the greatest number of times. When there is a tie for most occurrences, there are multiple mode values. Given a list of integers xs, return a list of all mode values. You must record them in the same order as their first occurrences are ordered in the original list. Assume:xs is a list of integers. Restrictions: you may not modify the original list, and you may not call any sorting functionality. But, you'll need to create your own lists, at a minimum for the answer, and it's likely you'll want to create some extra lists to help figure out the answer. o mode([1,5,2,5,4,5]) [5] mode([1,4,2,4,2,3]) [4,2] mode([1,2,3,4]) [1, 2, 3, 4] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started