[Tutor] python problem

Kent Johnson kent37 at tds.net
Thu Mar 1 16:54:36 CET 2007


> 
> From: "Purcell,  Brittany Nicole" <bnpurcel at indiana.edu>
> Date: 2007/03/01 Thu AM 01:40:45 EST
> To: tutor at python.org
> Subject: [Tutor] python problem
> 
> I have no idea how to even begin to program something like this and 
> what I need to do is:
> To complete the skeleton by replacing ellipsis (in this case vertical) 
> with a  solution. The number of dot indicates the number of lines of 
> the solution, and fill in the following dots:

This looks like homework to me. We won't do your homework for you. We will answer questions and help you when you have trouble but you have to try.

What have you learned so far in class? How might you apply that to these exercises?

Kent
> 
> def every_nth(s, n):
>     """Return a string composed of every n_th character of s, starting from the
>     first; that is, those characters with indices 0, 1*n, 2*n, ...
> 
>     >>> every_nth('abcdefg', 2)
>     'aceg'
>     >>> every_nth('abcdefg', 3)
>     'adg'
>     >>> every_nth('abcdefg', 1)
>     'abcdefg'
>     >>> every_nth('abcdefg', 20)
>     'a'
>     >>>
>     """
>     .
>     .
>     .
>     .
>     .
>     .
> 
> 
> def space_separate(s):
>     """Return a copy of string s with a space inserted between each of the
>     characters of string s.
> 
>     Use iteration over the characters of s.
> 
>     >>> assert space_separate('abc') == 'a b c'
>     >>> assert space_separate('') == ''
>     >>>
>     """
>     .
>     .
>     .
>     .
>     .
>     .
> 
> def reverse(s):
>     """Return a string with the characters of string s in reverse order.
> 
>     Implement with a while loop and indexing.
> 
>     >>> assert reverse('abc') == 'cba'
>     >>> assert reverse('') == ''
>     >>>
>     """
>     .
>     .
>     .
>     .
>     .
>     .
> 
> def test():
>     """Tests for this file."""
>     # add a few tests for each function below using assert statements
> 
> if __name__ == '__main__':
>     test()
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list