Downword Slant
Let’s call a word a "downword" if its letters are alphabetically sorted, case-insensitively, right to left. By this definition, Pond
is a downword because d
comes before n
, which comes before o
, which comes before P
. So too is pool
(as oo
does not violate this definition), but lake
is not because neither e
nor k
comes before a
alphabetically.
Answer the below in downword.txt
.
Questions
-
(1 point.) Is
spoonfed
a downword? -
(1 point.) Is
troll
a downword? -
(2 points.) Now imagine that we call a word an "upword" if its letters are alphabetically sorted, case-insensitively, left to right. Consider the below implementation in Python of
upword
, a function that returnsTrue
ifword
(astr
) is an upword andFalse
if it is not. Assume thatdownword
is a function (implemented elsewhere) that returnsTrue
ifword
is a downword andFalse
if it is not.def upword(word): return not downword(word)
Is this implementation of
upword
correct? Explain why or why not. -
(4 points.) Assume now that
downword
has not (yet!) been implemented elsewhere. Complete the implementation ofdownword
, below, in such a way that it returnsTrue
if and only ifword
(astr
) is a downword. ReturnFalse
ifword
contains one or more non-alphabetical characters or if the letters in word are not alphabetically sorted, case-insensitively, right to left.def downword(word): # TODO
Debrief
-
Which resources, if any, did you find helpful in answering this problem’s questions?
-
About how long did you spend on this problem’s questions?