PPA-7
Question
A sequence of five words is called magical if the \(i^{th}\) word is a substring of the \((i + 1)^{th}\) word for every \(i\) in the range \(1 \leq i < 5\). Accept a sequence of five words as input, one word on each line. Print magical
if the sequence is magical and non-magical
otherwise.
Note that str_1
is a substring of str_2
if and only if str_1
is present as a sequence of consecutive characters in str_2
.
Hint
The in
keyword is a powerful tool. For example, to see if a string word1
is a substring of another string word2
, you just need to type:
If word1
is a substring of word2
then this expression evaluates to True
. If not, it evaluates to False
. Now, it is just a question of repeatedly applying this condition across the sequence.