Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

make a program in python that satisfies the requirements below. please answer de

ID: 3723800 • Letter: M

Question

make a program in python that satisfies the requirements below. please answer design questions as well after completing the program.

C Chegg Study IGuided sc xHome C Secure | https://jhub.cas.mcmaster.ca/user/mehtaa13/notebooks/assign7 section/major3v2.ipynb jupyter major3_v2 (unsaved changes) Control PanelLogout File Edit View Insert Cell Kernel Help Not Trusted Python 3 O Background In this assignment you will implement a library of functions that can be used to encode and decode a list of lists of decimal (base 10) integers as binary (base 2) strings. The ints and binary strings will be stored in a list of lists. An example list or lists of ints would look like 18. 2. 38. 32, 10], 154. 71. 3]. 177. 95. 67. 341] Design, implement, and test a program that satisties the requirements below Requirements 1. Implement toBin(a) which takes a list of ints a and retums a new list where each entry in a is converted to a binary string using the Python function bin() 2. Implement tolnt(s) which takes a list of binary strings s and returns a new list where each entry in s is converted to an int value using the Python function int(x, 2) 3. Implement encode(A, n) which takes a list of lists of ints A and an int n and returns a new list of lists of strings where each entry in A has first been raised to the power of n, then converted to a binary string using toBin). Be careful not to modifyA 4. Implement decode(S, n) which takes a list of lists of binary strings s and an int n and returns a new list of lists of ints where each entry in S has first been converted to an int using tolnt). then raised to the power of 1/n. 11:30 AM O Type here to search Desktop.. ^UE,gxENG 2018-03-05

Explanation / Answer

def toBin(a):
    return [bin(i) for i in a]

def toInt(s):
    return [int(x, 2) for x in s]

def encode(A, n):
    result = []
    for a in A:
        encoded = [i**n for i in a]
        result.append(toBin(encoded))
    return result

def decode(S, n):
    result = []
    for x in S:
        decoded = toInt(x)
        result.append([i**(1/n) for i in decoded])
    return result

Solution to Design Questions

1. No, Even if toBin and toInt were modified to use hexadecimals conversions, no change would be needed in encode and decode because even though the encoded strings would now be different, after decoding the encoded string, the final result would still be the same as the original integer.

2. If the function has two return statement, the first return statement will only run as after that the control would no longer remain in that function and would shift to the caller program.

3. print() displays the parameters inside it to the screen. return is used to pass a value from the function to the caller program.

4. No, a function cannot access a variable defined in another function. This is because variables defined in a function aren't actually instantiated till the function is called and hence simply do not exist when another function is being executed. Hence to achieve this we use the return statement or pass a mutable data structure such as a list to the function.