Question: need help with python programming problem challenge: use Python lists to represent these. For example, suppose you have a set A = {1, 2, 3},

need help with python programming problem challenge:

use Python lists to represent these. For example, suppose you have a set A = {1, 2, 3}, a set B = {4, 5}, and a function f : A --> B, f = {(1, 4), (2, 5), (3, 4)}. This would be represented in Python as: A = [1, 2, 3] B = [4, 5] f = [ [1, 4], [2, 5], [3, 4] ]

1. Write a function isFunction(A, B, f) that determines whether the relation f is a function with the domain A and target B. A, B, and f are expressed using lists, as above. For example, calling isFunction(A, B, f) with the above variable values should return True.

2. Write a function image(f) that returns the image of the function f. The elements of the image should be sorted in ascending order. For example, calling image(f) with the above variable values should return the list [4, 5]. Python tip: You can sort a list like this: someList = sorted(someList)

3. Write a function isOneToOne(A, B, f) that determines whether the function f : A --> B is one-to-one. For example, calling isOneToOne(A, B, f) with the above variable values should return False.

4. Write a function isOnto(A, B, f) that determines whether the function f : A --> B is onto. For example, calling isOnto(A, B, f) with the above variable values should return True.

5. Write a function inverse(A, B, f) that returns the inverse of the function f : A --> B. If no inverse exists, return None (this is the Python equivalent of Javas null). For example, calling inverse(A, B, f) with the above variable values should return None. But if you were to define your variables like this: A = [1, 2, 3] B = [4, 5, 6] f = [ [1, 4], [2, 5], [3, 6] ] then calling inverse(A, B, f) should return something like [ [4, 1], [5, 2], [6, 3] ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!