A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 3 years ago

Hi fellow OCW students, I have a question about problem 2 on problem set 9 of 6.00 intro to computer science and programming. 1) I have no idea what I should do for def__iter__(self) part. I think I don't know what the iterator does in a class or sth. 2) http://paste.bradleygill.com/index.php?paste_id=3786 I get a error message after spitting out the right result as follows: Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> str(pj) TypeError: __str__ returned non-string (type NoneType) What did I do wrong here?

  • This Question is Closed
  1. anonymous
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    1) I don't know that mutch about the __iter__ method. You could try to see if you understand http://docs.python.org/2/library/stdtypes.html#iterator-types 2) The __str__ method expects you to return a string as the result of the method. You don't return anything, but you print directly. Try writing all the strings you now print into a variable. At the end of the method, you can return that variable. You shouldn't need to print anything yourself.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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


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