Welcome to the Mnemonic Phrase Validator Challenge! This Python challenge is designed to help you practise your coding skills while creating a useful tool for validating mnemonic phrases.
Mnemonic Phrase?
Mnemonic phrases are often used to remember specific sequences or information, such as the order of the planets in the solar system.
The following Mnemonic phrase makes it easier to remember the order of the planets as each word in this sentence starts with the letter corresponding to a planet in the solar system, matching their position from the Sun: from Mercury, closest planet to the Sun to Pluto, furthest planet to the Sun.
My Very Easy Method Just Speeds Up Naming Planets.
Mnemonic Phrase
As you can see this phrase contains all the planets in order: My (Mercury) Very (Venus) Easy (Earth) Method (Mars) Just (Jupiter) Speeds (Saturn) Up (Uranus) Naming (Neptune) Planets (Pluto – dwarf planet)
Python Challenge
For this challenge, you are going to write a Python program based on the Input/Process/Output model:
- Input: Accept a phrase from the user.
- Process: Define and implement validation rules to check the phrase.
- Output: Provide feedback to the user indicating whether the phrase is valid or not.
Validation Checks
To validate a mnemonic phrase we will use the following validation rules:
- Length: The phrase should be between 10 and 50 characters long.
- Unique Words: Each word in the phrase should be unique.
- Alphabetical Characters Only: The phrase should only contain alphabetic characters and spaces.
- Sequence Matching: Each word must start with the letter corresponding to the sequence we want to learn, in the same order. For example, if remembering the order of the planets, the phrase “My Very Easy Method Just Speeds Up Naming Planets” is valid because each word starts with the first letter of a planet’s name in order.
Let’s see how we can implement these four types of validation checks in Python:
In Python, we can use the len() function to find out the number of characters in a string.
phrase = "My Very Easy Method Just Speeds Up Naming Planets" if len(phrase)<10 or len(phrase)>100: print("Invalid: Phrase length should be between 10 and 100 characters.") return False
phrase = "My Very Easy Method Just Speeds Up Naming Planets" words = phrase.split()
We can then use the set() function in python which returns a set of unique values from a given list by removing duplicate values. If the resulting set contains as many words as the initial list of words, we can deduct that all the words in the words list must have been unique.
phrase = "My Very Easy Method Just Speeds Up Naming Planets" # Check for unique words words = phrase.split() if len(words) != len(set(words)): print("Invalid: Each word should be unique.") return False
To check the whole sentence, we will first create a list of words as we did in the previous check, using the split() function. We will then iterate through this list of words, to check one word at a time.
phrase = "My Very Easy Method Just Speeds Up Naming Planets" # Check for special characters words = phrase.split() for i in range(0,len(words)): if not words[i].isalpha(): print("Invalid: Phrase should only contain alphabetic characters and spaces.") break #No need to check other words
phrase = "My Very Easy Method Just Speeds Up Naming Planets" sequence = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune","Pluto"] valid = True # Check sequence matching for i in range(0,len(words)): if not words[i][0] == sequence[i][0]: print("Invalid: Each word must start with the corresponding letter in the sequence.") valid=False break #No need to check other words if valid==True: print("Valid Sequence Matching!")
Python Code
Your task is to use the techniques mentioned in the four tabs above to complete this Mnemonic Phrase Validator challenge.

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area