Insert Values in Python Array

Asked

Viewed 2,656 times

0

The point is that the values of bb,cc,dd nay are being inserted into the vectors vx,vy,vz.

vr=vx=vy=vz=[]
N=aa=bb=cc=dd=0
N=int(input())
for i in range(N):
    aa,bb,cc,dd=map(float, input().split())
    vr.append(aa)
    vx.append(bb)
    vy.append(cc)
    vz.append(dd)
    print(aa,bb,cc,dd)
    print(vr[i],vx[i],vy[i],vz[i])
  • 1

    What should this code do? What is the input and what is the output produced?

  • 3

    Do you understand that vr, vx, vy and vz are the same list right? There are 4 different lists.

  • Hmmmm, vlw! Bro, thanks a lot! I hadn’t thought of that.

  • 2

    How confusing this code.

  • I don’t know what your endgame is with this, or who’s gonna use it for what, but gather input("Digite quatro números separados por espaço: ") instead of just input() makes life easier for anyone running this program - even if it’s just you.

1 answer

2


I simply changed your initialization to separate the arrays (as you put it, they were the same thing) and removed the initialization line from the variables, as they do not seem to be necessary. See if you can do what you wanted.

vr=[]
vx=[]
vy=[]
vz=[]
N=int(input())
for i in range(N):
    aa,bb,cc,dd=map(float, input().split())
    vr.append(aa)
    vx.append(bb)
    vy.append(cc)
    vz.append(dd)
    print(aa,bb,cc,dd)
    print(vr[i],vx[i],vy[i],vz[i])

Browser other questions tagged

You are not signed in. Login or sign up in order to post.