Write a program which shows fx3x2 is a one to one function I
Write a program which shows f(x)=3x-2 is a “one to one” function. If you consider x as the set of positive integers 1 through 10, can we say it is “onto”? Why, or why not?
Solution
x = range(1,10)
y = []
for i in x:
y.append(3*i - 2)
for i in range(len(x)):
print x[i],\"<-->\",y[i]
# determine one - one
# for every value of x there should be value in y
# two or more values of x should not point to same value in y.
one_one = True
for i in range(len(y)):
va = x[i]
c = 0
for j in x:
if j==va:
c += 1
if(c!=1):
one_one = False
print \"one-one:\",one_one
#determine onto
# for every value of y there should be value in x.
onto = True
for i in range(len(y)):
if(not x[i]):
onto = False
print \"Onto:\",onto
\"\"\"
sample output
1 <--> 1
2 <--> 4
3 <--> 7
4 <--> 10
5 <--> 13
6 <--> 16
7 <--> 19
8 <--> 22
9 <--> 25
one-one: True
Onto: True
\"\"\"
