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