The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please do problems 2 and 3 by python 3.0 .
Do not import any Python packages such as math or numpy to complete this assignment.
These questions require only the standard Python library.
Thanks a lot!
Â
Â
MATH 210 Assignment 3
More Logic, Loops and Functions INSTRUCTIONS
â—¦ Create a new Python 3 Jupyter notebook
â—¦ Answer each question in the Jupyter notebook and clearly label the solutions with headings
â—¦ Functions should include documentation strings and comments
â—¦ There are 15 total points and each question is worth 3 points
â—¦ Submit the .ipynb file to Connect by 11pm Monday, January 30, 2017
â—¦ You may work on these problems with others but you must write your solutions on your own
â—¦ Do not import any Python packages such as math or numpy to complete this assignment.
These questions require only the standard Python library. Solutions will be given 0 if any
Python package/module is used.
QUESTIONS
1. Write a function called prime_divisors which takes one input parameter N (a positive
integer) and returns a Python list of prime numbers which divide N . For example:
prime_divisors(21) returns [3,7]
prime_divisors(24) returns [2,3]
prime_divisors(1815) returns [3,5,11]
2. Write a function called prime_factorization which takes one input parameter N (a positive
integer) and returns a Python list of tuples [(p1 , n1 ), . . . , (pm , nm )] which gives the factorization of N into primes:
N = pn1 1 pn2 2 · · · pnmm
For example:
prime_factorization(21) returns [(3,1),(7,1)] since 21 = 31 · 71
prime_factorization(24) returns [(2,3),(3,1)] since 24 = 23 · 31
prime_factorization(1815) returns [(3,1),(5,1),(11,2)] since 1815 = 31 · 51 · 112 3. Given a finite sequence of positive integers [a0 , a1 , . . . , an ] (of length n + 1), define a new finite
sequence [b0 , b1 , . . . , bn ] (defined recursively) by
b0 = a0
1
1
= a1 +
b0
a0
1
1
b2 = a2 +
= a2 +
b1
a1 + a10
1
1
b3 = a3 +
= a3 +
b2
a2 + a +1
b1 = a1 + 1 1
a0 ..
.
bn = an + 1
bn−1 = an + 1
.. .+ 1
a0 Write a function called sequence_to_fraction which takes one input parameter integer_list
(a Python list of positive integers [a0 , a1 , . . . , an ]) and returns the last number bn in the sequence defined above
1
bn = an +
an−1 + 1
.. 1
.+ a
0 For example:
sequence_to_fraction([1,1]) returns 2.0
sequence_to_fraction([1,1,1,1,1,1,1,1,1,1,1]) returns 1.6179775280898876
sequence_to_fraction([6,1,1,4,1,1,2,1,2]) returns 2.718279569892473
sequence_to_fraction([2,1,1,1,292,1,15,7,3]) returns 3.141592653581078
4. Define a function called product which takes a Python list of numbers and returns the product
of the numbers in the list. For example:
product([1,2,3,4]) returns 24
product([2,3,5,7,11,13]) returns 30030
product([0.5,0.25,0.125]) returns 0.015625
5. Write a function called sequence_to_roots which takes one input parameter integer_list
(a Python list of positive integers [a0 , a1 , . . . , an ]) and returns the number
s
r
q
√
an + an−1 + · · · + a0
For example:
sequence_to_roots([1,1]) returns 1.4142135623730951 (ie. p
√
1 + 1)
s
r q
p
√
sequence_to_roots([2,2,2,2,2]) returns 1.9975909124103448 (ie. 2 + 2 + 2 + 2 + 2)
q
p
√
sequence_to_roots([1,2,3]) returns 2.1753277471610746 (ie. 3 + 2 + 1)
-----------