After months of adventure on the mysterious island of Xylogora, young explorer Mateo has finally returned home. His backpack is stuffed with notes, sketches, and a collection of breathtaking photos of creatures never seen before. From the feathered glimmerfox to the six-legged rippletoad, each animal was stranger and more exotic than the last.
But Mateo has a problem: Every great discovery needs a name, and he has dozens of new species waiting to be named and documented.
Pulling out his laptop, Mateo decides to create a naming algorithm using string-handling techniques. His plan is simple yet ingenious: take the names of existing animals, rearrange their letters, or combine parts of their names to create unique ones. For instance, the “Wolphin” might come from “Wolf” and “Dolphin”.
String Handling Techniques
To create his algorithm, Mateo will need to use the following string handling techniques:
- LEFT: to extract characters at the beginning of a string,
- RIGHT: to extract characters at the end of a string,
- SUBSTR or MID: to extract a set number of characters at a given position in a string,
- LENGTH: to find out the number of characters in a string,
- String Concatenation: to join two or more strings together.
For instance:
LEFT(“WOLF”, 3) would return “WOL”.
For instance:
RIGHT(“DOLPHIN”, 4) would return “PHIN”.
For instance:
SUBSTR(“PANDA”, 1, 3) would return “AND”.
For instance:
“WOL” + “PHIN” would return “WOLPHIN”.
For instance:
LENGTH(“DOLPHIN”) would return 7.
Naming Unknown Species
Can you work out the name given to the following species?
Python Challenge
Can you help Mateo by writing a Python program that generates exotic animal names using string handling techniques? Your program will need to:
-
Takes two (or more) animal names as inputs.
Randomly combines parts of each name to create a new species name.
Output the generated name.
Let the user decide if they like the name or if the computer should have another go.
To do so you will need to complete the code provided below:
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area