Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.0 Help!! book1 = { squirtle : [wartortle], wartortle : [blastoise], blastoise : [], charmander : [charmeleon], charmeleon : [charizard], charizard : [], bulbasaur

Python 3.0 Help!!

image text in transcribed

book1 = { "squirtle" : ["wartortle"], "wartortle" : ["blastoise"], "blastoise" : [], "charmander" : ["charmeleon"], "charmeleon" : ["charizard"], "charizard" : [], "bulbasaur" : ["ivysaur"], "ivysaur" : ["venusaur"], "venusaur" : [] } book2 = { "eevee" : ["jolteon", "flareon", "vaporeon"], "jolteon" : ["zapdos"], "vaporeon" : ["articuno"], "flareon" : ["moltres"] } 
Degree of Difficulty: Tricky Pokemon are fantastic creatures that can evolve into other, usually stronger, creatures. In their secret laboratory, the evil Team Rocket has been trying to evolve Pokemon in terrifying new ways! Might it now be possible for a meek Magikarp to evolve all the way into the mighty Mewtwo? Your job is to use the power of recursion to write a program to find out. For this problem you will be given a pokemon evolution book as a dictionary. The keys to this dictionary are pokemon names, and the value for each key is a list of pokemon that can be evolved into The following is a sample of what this dictionary might look like book vartortle squirtle blasts oise vartortle blast oise flare on jolteon Vaporeon In the example above, squirtle can (eventually) evolve into a blastoise by first evolving into a wartortle, but never into an eevee. On the other hand, eevee can evolve into any one of flareon, jolteon or vaporeon. Note that a pokemon that can no longer evolve might be in the book and associated with an empty list (like blastoise above) or might not be in the book at all. Either case is fine and your program needs to handle both cases correctly You are guaranteed, however, that the pokemon b will be structured such that a pokemon cannot "devolve". Thus, if ook pokemon A can, ther directly or indirectly, evolve into pokemon B, then it will not be possible for B to evolve back into A. Your task is to write a recursive function that will answer the question of whether a source pokemon can eventually evolve into a given target pokemon. Your function should have 3 parameters: the source, the target and the pokemon dictionary to use to check for possible evolutions. Your function should return True if it is possible for source to become the target and False otherwise This might sound a little difficult, but with the power of recursion, this is not a complicated problem. Your function should be no longer than 12 lines of code not counting comments) and possibly less (ours is 8). If you find your solution is getting any longer than that, you are overthinking it! Sample Run We are providing you with 3 sample pokemon books to use; you can find these on the Moodle and you can just copy/paste the dictionary literals into your code. If you test your program with the sample code provided, you should get ouput that looks like this: Using book1 can bulbasaur evolve to venus aur? True Using book1 charmeleon evolve to blastoise? False Using book2 evolve to articuno? True Using book3 can cubone evolve to charizard? Falne Using book3 can magikarp evolve to mewtwo? True

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 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions