some problems for an introductory python test

Hope Rouselle hrouselle at jevedi.xotimo
Mon Aug 9 17:07:42 EDT 2021


I'm looking for questions to put on a test for students who never had
any experience with programming, but have learned to use Python's
procedures, default arguments, if-else, strings, tuples, lists and
dictionaries.  (There's no OOP at all in this course.  Students don't
even write ls.append(...).  They write list.append(ls, ...)).

I'd like to put questions that they would have to write procedures that
would would be real-world type of stuff, without error checking,
exceptions and such.  So if you think of something more or less cool
that uses loops, we can sometimes simplify it by assuming the input has
a certain fixed size.

I came up with the following question.  Using strings of length 5
(always), write a procedure histogram(s) that consumes a string and
produces a dictionary whose keys are each substrings (of the string) of
length 1 and their corresponding values are the number of times each
such substrings appear.  For example, histogram("aaaaa") = {"a": 5}.
Students can "loop through" the string by writing out s[0], s[1], s[2],
s[3], s[4].

I'd like even better questions.  I'd like questions that would tell them
to write procedures that would also have inverses, so that one could
check the other of the other.  (A second question would ask for the
inverse, but hopefully real world stuff.  One such question could be
parsing a line separate by fields such as "root:0:0:mypass:Super User"
and another that gives them ["root", 0, 0, ...] and asks them to write
"root:0:0:mypass:..."  You get the idea.)

Students know how to use str().  But they don't know how to use type(),
so they can't really check for the type of the input.  I probably
couldn't ask them to write a prototype of a tiny subset of pickle, say.

I think you get the idea.  I hope you can provide me with creativity.  I
have been looking at books, but every one I look at they introduce loops
very quickly and off they go.  Thank you!


More information about the Python-list mailing list