'while loop to create a list of new class objects
I am new to python and am using it for some classes, I am trying to figure out how to generate a list of objects. I created a class data type and I want to use a while loop to quickly generate multiple objects of that new data type and store them in a list. the code I have now is down below, I have it set up to (if it worked) make a list (v), start a loop contingent on confirming to loop again, track how many times we have looped with i, create and append a cart_vect (class data type with 3 numeric tags that are prompted for input imported from another set of code) to the list v. loop creating a list of objects and (for now) print the list of objects. I have tried to work it out and find solutions online already but I cant seem to get an answer.
v=[]
cont='y'
i=1
while cont=='y':
v.append(v[-1]+1)
print('vector',i,':')
v[-1]=cart_vect(float(input('x:')),float(input('y:')),float(input('z:')))
i=i+1
cont=input('another vector? y/n ')
print(v)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
