Question: python 3 A spiral word is a word where the sequence of characters defined by spiraling over the letters from outside in, is in strictly

python 3

A spiral word is a word where the sequence of characters defined by spiraling over the letters from outside in, is in strictly ascending or descending order. When we spiral over the letters, we start with the first letter, then examine the last letter, then the second letter, followed by the second-last letter, etc, spiraling towards the middle letter. For example, in the case of 'urgent', the letter sequence defined by the spiral is 'u' (the first letter), 't' (the last letter), 'r' (the second letter), 'n', 'g', and finally 'e', as illustrated below:

python 3 A spiral word is a word where the sequence of

In this case, the spiralled sequence of letters is in strictly descending order, as each letter comes before its (spirally) preceding letter in the alphabet. An example of an ascending spiral word (where every letter comes after its (spirally) preceding letter) is 'flush' ('f', 'h', 'l', 's', 'u'). An example of a non-spiral word, on the other hand, is 'all', as the spiral sequence of letters is not strictly ascending ('l' follows 'l').

Write the function spiral_word(word) that takes a single string argument word and returns a 2-tuple made up of bool values as follows:

the first bool indicates whether the word is a spiral word or not

the second bool indicates whether a spiral word is ascending or not (indicating either that it is descending, or that it's not a spiral word).

For example, 'urgent' should generate the output (True, False), 'flush' should generate the output (True, True), and 'all' should generate the output (False, False) (indicating that the word is not spiral, and also not an ascending spiral word). Note that (False, True) is an invalid output, as it is not possible for a word to not be a spiral word, but to be an ascending spiral word. You may assume that word contains at least 2 letters, and that all letters are in lower case.

Here are some example calls to your spiral_word function:

>>> spiral_word('urgent') (True, False) >>> spiral_word('flush') (True, True) >>> spiral_word('all') (False, False)

u r g e n t

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!