[Tutor] python problem
Purcell, Brittany Nicole
bnpurcel at indiana.edu
Thu Mar 1 07:40:45 CET 2007
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:
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()
More information about the Tutor
mailing list