Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JulieNewbie

  • 3 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
  1. tonybaldwin
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I 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.

  2. tonybaldwin
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    commAnd (not commend...can't type today)

  3. JulieNewbie
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    tonybaldwin, 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?

  4. bwCA
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 2

    it 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#set-types-set-frozenset the difference method does what you want. here are some examples: http://codepad.org/JjnYoyVU without using sets - http://codepad.org/M1ExloXK

  5. AdisA
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I 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

  6. JulieNewbie
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Thank you guys! I'll tinker around with your suggestions.

  7. thearchie
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    2 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?

  8. bwCA
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 2

    there 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

  9. thearchie
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I 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.

  10. JulieNewbie
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I, 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.

  11. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.