Question
Using python 3.0 or greater. I need help writing this recursive function. Write a recursive function that is able to tell if a pokemon can
Using python 3.0 or greater. I need help writing this recursive function.
Write a recursive function that is able to tell if a pokemon can to evolve into a given target pokemon.
The function will have three parameters, a source, target and a dictionary containing the pokemon and their
evolutionary lineage. The source being the pokemon in question and the target being if the source pokemon can
evolve into the target pokemon. No de-evolution can take place.
Example of a dictionary.
book = { |
"squirtle" : ["wartortle"], "wartortle" : ["blastoise"], "blastoise" : [], "eevee" : ["flareon", "jolteon", "vaporeon"] } |
"blastoise" : [], represents its final form and can't evolve anymore.
Here is what I got so far.
def evolution(source,target,book): if book[source]==[]: return False elif book[source]!= target: for x in book[source]: source=x return source elif book[source]== target: return True else: return evolution(source,book[target],book)
Thanks for the help.
Step 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