Brian Blais wrote: > I have a couple of classes where I teach introductory programming using > Python. What I would love to have is for the students to go through a > lot of very small programs, to learn the basic programming structure. > Things like, return the maximum in a list, making lists with certain > patterns, very simple string parsing, etc. Unfortunately, it takes a > lot of time to grade such things by hand, so I would like to automate it > as much as possible. > > I envision a number of possible solutions. In one solution, I provide a > function template with a docstring, and they have to fill it in to past > a doctest. Is there a good (and safe) way to do that online? Something > like having a student post code, and the doctest returns. I'd love to > allow them to submit until they get it, logging each attempt.
A few people were playing around with a secure Python online interpreter/interactive prompt a while back: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/66e659942f95b1a0/6f46d738a8859c2f I don't think any of them was quite at the usability level you'd need though. Can you just have the students download one file for each program you want them to run? I'd ship something like:: import unittest # ======================================== # This is the function you need to fill in # ======================================== def list_max(items): '''Your code goes here''' # ================================== # Don't modify code below this point # ================================== class Test(unittest.TestCase): def test_range(self): self.failUnlessEqual(list_max(range(10)), 10) def test_first_elem(self): self.failUnlessEqual(list_max([1, 0, 0, 0]), 1) ... if __name__ == '__main__': unittest.main() Then all your students would have to do is download the file, fill in the definition of the appropriate function, and run the same file until the unittest said that everything worked. I guess that doesn't solve your "logging each attempt" problem though... STeVe -- http://mail.python.org/mailman/listinfo/python-list