Your problem solving steps should be included in the header comments for each problem. We suggest you run your own tests before submitting. For example you can call the function and print the return...

1 answer below »

Your problem solving steps should be included in the header comments for each problem. We suggest you run your own tests before submitting. For example you can call the function and print the return value:


print(log_base_2(256))


But thenremovethese before submitting because they will use WebCAT server time.



Theonlyfunctions you may use are:len and range, note that you may not use slicing(AKA colons in your indices). *We will not deduct for the use of str(), but you do not actually need it.
*Do not import packages.



Sample HW Solution:ExampleHW.py



Coding Template for this assignment:HW4.py


Be sure to download and use the template file, if you copy and paste code from a website/pdf you will likely encounter invalid characters.



Name conventions reference:Be sure to follow python naming conventions and add comments when clarity is neededhttps://www.python.org/dev/peps/pep-0008/#naming-conventions.

Problem Descriptions:Design and code a python solution for the problems. You must come up with your own algorithm and the honor code applies (no references).


1. [50 points] Design an algorithm that will use simple arithmetic operations to estimate the base-2 logarithm of a given positive number. The algorithm should report the exact answer if it is an integer and otherwise state upper and lower bounds for it.


For example, given the input 256, your algorithm should report 8, and given the input 81 your algorithm should report the logarithm lies between 6 and 7. Note that numbers less than 1 but greater than zero are positive.(Your solution may
not
invoke a log function/operator.)



(parts i - iii should be in your function header comment, see Sample HW Example above)


i. Work out the steps to figure out the 2 concreteexamples of 256 and 81 step by step and briefly explain your work and thinking(5pts)


ii. Find and describe a pattern and attempt to generalize (5pts)


iii. Investigate and explain special cases to see if the pattern holds up (5pts)


iv. Come up with a solution and write a python functionlog_base_2(number)that returns either an exact value or range (35pts)



  • Think about how you format your return string, call your function withvarious numbers to test it

    • the call log_base_2(256) shouldreturn: "8"

    • the call log_base_2(81) shouldreturn: "between {lower bound} and {upper bound}"






2. [50 points] Design an algorithm that will take a list of numbers and reverse the order of the elements in the list, without making use of a second list variable.(Your solution may not use python's reverse function or slicing.)


Example of the algorithm:


Input = [1, 2,3, 4, 5,6, 7,8]


Output = [8, 7, 6, 5, 4, 3, 2,1]


----------------------------------------------------


Input = [1, 2,3, 4, 5, 6,7, 8,9]


Output = [9, 8, 7, 6, 5, 4, 3, 2, 1]


----------------------------------------------------


Input = [1,2]


Output = [2,1]


----------------------------------------------------


Input = [1, 2 ,3]


Output = [3, 2 ,1]


----------------------------------------------------



(parts i - iii should be in your function header comment, see Sample HW Example above))


i. Work out the steps to figure out a concrete example and briefly explain your work and thinking(5pts)


ii. Find and describe a pattern and attempt to generalize (5pts)


iii. Investigate and explain special cases to see if the pattern holds up (5pts)


iv. Come up with a solution and write your own python functionreverse_list(alist)that reverses the list (35pts)



  • The function shouldreturn the altered list.

  • Call your function withvarious lists to test it, print the list before and after the call to test it.

FROM RUBRIC-5 for list functions
-20 for using a function not allowed
-50 for using an extra list-35for expanding the list
Answered Same DaySep 17, 2021

Answer To: Your problem solving steps should be included in the header comments for each problem. We suggest...

Arun Shankar answered on Sep 18 2021
148 Votes
'''
(i) Concrete example
A = [1, 2, 3, 4, 5, 6, 7, 8]
Swap 1 with 8 A = [8, 2, 3, 4, 5, 6, 7, 1
]
Swap 2 with 7 A = [8, 7, 3, 4, 5, 6, 2, 1]
Swap 3 with 6 A = [8, 7, 6, 4, 5, 3, 2, 1]
Swap 4 with 5 A = [8, 7, 6, 5, 4, 3, 2, 1]
Keep swapping from either ends until we reach the
middle of the list.
(ii) If the list has 10...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here