Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

DESCRIBE the three steps in the collective bargaining process.

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago