Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 21 Online
OpenStudy (anonymous):

I'm working on PS2 and am wondering if there is a way to add values derived from a program to a list? Ultimately, I'd need to use this list outside the program as a reference to check values from a separate program against. I haven't seen anything on this in the readings yet. I've just about completed the readings for lecture 3. Can someone point me in the right direction or is this not something you can do in Python?

OpenStudy (anonymous):

Lists objects have an 'append' method that adds elements to them. If you want to use your values in another program you'll have to write them out to a file, and read in the other program.

OpenStudy (anonymous):

Lists can also be concatenated by using the + operator, which has a different behavior from the .append function. This is covered later in lecture 6 around 44min. I'm guessing you are looking for a way to keep track of the possibilities to do the calculation for ps2. A copy of the solution I came up with is at http://dpaste.com/533804/ . You can see that I added possibilities to the variable bestSoFar using the + operator. Hope this helps!

OpenStudy (anonymous):

thanks knowak and jls. i'll look into both these options. i'm not certain how to read the list back into a separate program so i might come back to get some advice on this later.

OpenStudy (anonymous):

knowak, any tips on how to read in my list of possible nuggets that can be bought? take a look at my code so far. line 17 is where i try to use the list generated from the top portion of my program. the error message i get indicates that the list isn't callable. i understand what that means but i don't know how to fix it. http://dpaste.com/534695/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!