A community for students.
Here's the question you clicked on:
 0 viewing
JulieNewbie
 4 years ago
I'm working on ps2, part 3. I made a function which will create a list of all the possible numbers of nuggets you can get. The list should incrementally increase as python finds solutions, but my list isn't growing. Can anyone tell why the list only contains the final solution?
http://codepad.org/6IufXoEb
JulieNewbie
 4 years ago
I'm working on ps2, part 3. I made a function which will create a list of all the possible numbers of nuggets you can get. The list should incrementally increase as python finds solutions, but my list isn't growing. Can anyone tell why the list only contains the final solution? http://codepad.org/6IufXoEb

This Question is Closed

tonybaldwin
 4 years ago
Best ResponseYou've already chosen the best response.0I THINK it's because you're only telling it to append the last solution. If you want to append early in the looping loops, you'll have to unindent. The append commend belongs to the last loop, only, because it is intended after it. I have barely just completed ps1b, so haven't gotten to this ps2* at all, but that's my guess.

tonybaldwin
 4 years ago
Best ResponseYou've already chosen the best response.0commAnd (not commend...can't type today)

JulieNewbie
 4 years ago
Best ResponseYou've already chosen the best response.1tonybaldwin, you're right. OMG I figured this out about 10 minutes after I shut down my computer. I'll leave this question up just to make everyone else feel really smart. STUPID question. Hopefully this question is slightly less stupid: I'm wondering if it's possible to print things NOT in a list. For example: >>> mylist = [1, 3, 5] >>> mylist.NotThere in range (1, 6) ## and Python would know what the heck I'm talking about and return: [2, 4] Is that possible?

bwCA
 4 years ago
Best ResponseYou've already chosen the best response.2it is possible. python has a data type that you haven't been introduced to that makes it easy. http://docs.python.org/library/stdtypes.html#settypessetfrozenset the difference method does what you want. here are some examples: http://codepad.org/JjnYoyVU without using sets  http://codepad.org/M1ExloXK

AdisA
 4 years ago
Best ResponseYou've already chosen the best response.0I think it isn't possible when element are in the list. Look at this http://docs.python.org/tutorial/datastructures.html There is no method for doing that. I have done it this way: http://codepad.org/Sz1yhg2m

JulieNewbie
 4 years ago
Best ResponseYou've already chosen the best response.1Thank you guys! I'll tinker around with your suggestions.

thearchie
 4 years ago
Best ResponseYou've already chosen the best response.02 questions about the above: 1) aren't you supposed to iterate beginning with n = 1? 2) there has to be a way to write the code using only the things learned in the preceding lectures, right?

bwCA
 4 years ago
Best ResponseYou've already chosen the best response.2there are readings associated with the lectures also. and the actual course at the institute has 'study sessions' outside of lecture with TA's/grad students  that we don't get at ocw. I can't imagine that a college level course would prohibit you from seeking knowledge not presented in lecture and then prohibit you from using it to solve the assignments

thearchie
 4 years ago
Best ResponseYou've already chosen the best response.0I am thinking of it more like "approach the problem with only these tools, b/c that's all you'll need". I apologize if my previous post came across negatively. I meant that I find having to do the assignments with the limited information presented in preceding lectures and readings quite challenging, and if students in the actual course might have gotten away with using more advanced code. I also forgot about the study sessions.

JulieNewbie
 4 years ago
Best ResponseYou've already chosen the best response.1I, too, found it really frustrating to do the problem sets as they occurred with the lectures & readings. PS1 didn't work for me until after the 4th or 5th lecture & readings. So rather than continuously be frustrated, I decided that I'm thinking more like a computer scientist if I'm NOT relying only upon the tools I've learned. As a result, I'm several lectures ahead of the problem sets I'm working on. Whether you strictly follow the syllabus or approach it some other way, I think you'll end up in about the same place. But there's no certificate, no grade. So ultimately it doesn't really matter how you get there. Just do what works for you.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.