Generation

generate functionTue, 25 Apr 2023

Dados 2 vectores A y B de 10 elementos cada uno; realizar el cálculo entre ellos para las operaciones aritméticas de suma, resta, multiplicación y división en un tercer vector (validar la división por 0), de los elementos correspondientes de los vectores A y B.

//define the vectors A = [1,2,3,4,5,6,7,8,9,10] B = [1,2,3,4,5,6,7,8,9,10] C = [] //define the operations def suma(a, b): return a + b def resta(a, b): return a - b def multiplicacion(a, b): return a * b def division(a, b): return a / b //if a or b == 0: //return 0 //else: //return a/b //get the values of the vectors for i in range(10): C.append(suma(A[i], B[i])) //print the result print(C)

Questions about programming?Chat with your personal AI assistant