Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

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 "", line 1, in str(pj) TypeError: __str__ returned non-string (type NoneType) What did I do wrong here?

OpenStudy (anonymous):

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.

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!