Python Codes

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

def is_function(relation):

domain = set()
for pair in relation:
if pair[0] in domain:
return False
else:
domain.add(pair[0])
return True

# Example usage:
relation1 = [(1, 2), (2, 3), (3, 4), (1, 5)]
print(is_function(relation1)) # Output: False

relation2 = [(1, 2), (2, 4), (3, 6)]


print(is_function(relation2)) # Output: True

def evaluate_function(func, value):


return func(value)

# Example usage:
def f(x):
return 3 * x - 2

print(evaluate_function(f, 4)) # Output: 10


print(evaluate_function(f, -1)) # Output: -5

def evaluate_function_at_points(func, points):


results = []
for point in points:
results.append(func(point))
return results

# Example usage:
def g(x):
return x ** 2 + 1

points = [2, -3, 0]


print(evaluate_function_at_points(g, points)) # Output: [5, 10, 1]

You might also like