I have a C++ code here which inputs some attributes for n objects of a class named stock.
1 2 3 4 5 6 7 8 9 10 11
|
int counter=0;
Stock* stock = new Stock[n]; //creating n stocks
while (n--) {
cout << "Enter ticker> " << flush;
cin >> stock[counter].ticker;
cout << "Enter current price> " << flush;
cin >> stock[counter].currentPrice;
cout << "Enter target price> " << flush;
cin >> stock[counter].targetPrice;
counter++;
}
| |
I'm trying to convert the same code to python but I can't figure it out. Here's my python code (which contains a lot of errors of course)
1 2 3 4 5 6 7 8
|
counter=0
stock= []
while (n!=0):
stock[counter].ticker=(input("Enter ticker> "))
stock[counter].currentPrice= float(input("Enter current price> " ))
stock[counter].targetPrice=float(input( "Enter target price> " ))
counter+=1
n-=1
| |
Any suggestions/ corrections are appreciated!
Last edited on
Last edited on