1
Make a program that fills two vectors of five numerical elements each and shows the vector resulting from their intercalation. Vectors must be initialized with the values below:
https://photos.app.goo.gl/egHj5dYLAXxfbLoW6
First I decided to make a smaller version, where the third vector will have only 5 elements. I got it here(in case the view is confused, the code is more organized in Google Docs: https://docs.google.com/document/d/13poguwUMA4y3mumadOkDJgarwzqx_vr-HkZgw9MMmg4/edit?usp=drivesdk):
vetor1 = [0]*5
vetor1[0] = 4
vetor1[1] = -9
vetor1[2] = 78
vetor1[3] = 0
vetor1[4] = 25
print(vetor1)
vetor2 = [0]*5
vetor2[0] = 8
vetor2[1]= 2
vetor2[2] = 34
vetor2[3] = 90
vetor2[4]= 200
print(vetor2)
v3 = [0] * 5
for i in range(5):
if i%2 == 0:
v3[i] = vetor1[i/2]
else:
And this is where I start to have problems. I can’t find a formula to relate all v3 and v2 indexes.
Much more pythonica! + 1
– Luiz Augusto
I did not understand the functioning of the structure " x for par in zip(a,b)"
– Pablo Leonardo
@Pabloleonardo in mathematical language, this is usually written as
[ x | par ∈ zip(a,b) ∧ x ∈ par ]
– JJoao