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:
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 tStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started