-1

I have a lab where in one part I need to use the array:

A = [3, 3, 20, 8, -2, 1, 3, -7, 2, 1, 3, -5, 13]

and I have to run all the elements of that array in this equation Y = 3x + 2, the x will be the elements of the array A and all the elements need to be used there, but I don't know how to make this. Also, it needs to be in a function with the name Ecuacion, e.g.: def Ecuacion():`

Edit: Then I need to print the elements I got from the equation.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
SaryxEze
  • 1
  • 2

3 Answers3

1

A simple for loop should do the trick:

for x in A:
    y = 3 * x + 2
    print(y)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Is this what you want?

def func(A):
    B = list(map(lambda x: x * 3 + 2, A))
    return B

A = [3, 3, 20, 8, -2, 1, 3, -7, 2, 1, 3, -5, 13]
print(func(A))
Ihmon
  • 183
  • 1
  • 13
0

That should work

def ecuacion(x):
    B = []
    for i in x:
        y = 3*i + 2
        B.append(y)
    return B

A = [3, 3, 20, 8, -2, 1, 3, -7, 2, 1, 3, -5, 13]
print(ecuacion(A))

Output:

[11, 11, 62, 26, -4, 5, 11, -19, 8, 5, 11, -13, 41]
simoncraf
  • 146
  • 5