Write a Python program, in a file called forest_map.py, to solve the following problem: Hansel and Gretel are abandoned in a forest with only a bag of breadcrumbs and must find their way home. The forest is laid out in a grid pattern. They can only take a step at a time through the forest, going either South or East. They cannot move diagonally, they cannot move North, and they cannot move West. As they leave a space, they will leave a breadcrumb (“*”) behind just in case -- if they have any breadcrumbs left. They do not leave a breadcrumb in the space where the path ends. If they don’t have enough breadcrumbs, they still move on to the next space, leaving their current space as it was. Given (as input) the number of breadcrumbs Hansel and Gretel have, and given the forest layout (as a fixed, but changeable, two-dimensional list in your code), determine whether Hansel and Gretel have just enough, more than enough, or not enough, breadcrumbs to leave in the path to get to the end. If they have more than enough, display how many breadcrumbs remain. An empty space (‘ ’) in the forest layout denotes a path and an ‘X’ in the forest layout denotes a tree in the forest. Hansel and Gretel cannot move where a tree is. The end of the path is denoted by an ‘E’ in the lower right-hand corner of the forest. Hansel and Gretel always start in the upper left-hand corner of the forest. There is always only one direction that they can move in, they will never have to choose between South and East. Your program must include the following: • function main that contains the forest layout as a list (you can just make it up here, it doesn’t have to be input, but the sizes of the dimensions should be flexible and the starting position always has to be in the top left corner of the list); it asks the user for the number of breadcrumbs as an integer; it should print the resulting forest map showing the breadcrumbs (just print the 2-D list, it doesn’t have to be formatted) and also make use of the following functions to compute and print the message to the user • function distance which takes, as parameters, the forest layout and the initial number of breadcrumbs, and returns the number of breadcrumbs they used to get to the end – this value will be negative if they run out before reaching the end; remember, unknown to Hansel and Gretel but known to you, the path only continues either East or South, and there is only one path and no dead-ends • function crumbsLeft which takes, as a parameter, the number of breadcrumbs left (which may be negative if the path is longer than the number of breadcrumbs) and prints that there were not enough breadcrumbs, just enough breadcrumbs, or the actual amount of breadcrumbs left For example, given the following forest map: forestPath = [[' ',' ',' ','X','X'],\ ['X','X',' ',' ','X'],\ ['X','X','X',' ','X'],\ [' ','X','X',' ',' '],\ [' ','X','X','X',' '],\ [' ',' ','X','X',' '],\ [' ',' ','X','X','E']] If the number of breadcrumbs given is 12, sample output would be: Enter number of breadcrumbs: 12 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', '*', 'X'], [' ', 'X', 'X', '*', '*'], [' ', 'X', 'X', 'X', '*'], [' ', ' ', 'X', 'X', '*'], [' ', ' ', 'X', 'X', 'E']] 2 breadcrumb(s) are left If the number of breadcrumbs given is 5, sample output would be: Enter number of breadcrumbs: 5 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', ' ', 'X'], [' ', 'X', 'X', ' ', ' '], [' ', 'X', 'X', 'X', ' '], [' ', ' ', 'X', 'X', ' '], [' ', ' ', 'X', 'X', 'E']] Not enough breadcrumbs for the trip. If the number of breadcrumbs given is 10, sample output would be: Enter number of breadcrumbs: 10 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', '*', 'X'], [' ', 'X', 'X', '*', '*'], [' ', 'X', 'X', 'X', '*'], [' ', ' ', 'X', 'X', '*'], [' ', ' ', 'X', 'X', 'E']] Phew, just enough breadcrumbs for the trip.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a Python program, in a file called forest_map.py, to solve the following problem: Hansel and Gretel are abandoned in a forest with only a bag of breadcrumbs and must find their way home. The forest is laid out in a grid pattern. They can only take a step at a time through the forest, going either South or East. They cannot move diagonally, they cannot move North, and they cannot move West. As they leave a space, they will leave a breadcrumb (“*”) behind just in case -- if they have any breadcrumbs left. They do not leave a breadcrumb in the space where the path ends. If they don’t have enough breadcrumbs, they still move on to the next space, leaving their current space as it was. Given (as input) the number of breadcrumbs Hansel and Gretel have, and given the forest layout (as a fixed, but changeable, two-dimensional list in your code), determine whether Hansel and Gretel have just enough, more than enough, or not enough, breadcrumbs to leave in the path to get to the end. If they have more than enough, display how many breadcrumbs remain. An empty space (‘ ’) in the forest layout denotes a path and an ‘X’ in the forest layout denotes a tree in the forest. Hansel and Gretel cannot move where a tree is. The end of the path is denoted by an ‘E’ in the lower right-hand corner of the forest. Hansel and Gretel always start in the upper left-hand corner of the forest. There is always only one direction that they can move in, they will never have to choose between South and East. Your program must include the following: • function main that contains the forest layout as a list (you can just make it up here, it doesn’t have to be input, but the sizes of the dimensions should be flexible and the starting position always has to be in the top left corner of the list); it asks the user for the number of breadcrumbs as an integer; it should print the resulting forest map showing the breadcrumbs (just print the 2-D list, it doesn’t have to be formatted) and also make use of the following functions to compute and print the message to the user • function distance which takes, as parameters, the forest layout and the initial number of breadcrumbs, and returns the number of breadcrumbs they used to get to the end – this value will be negative if they run out before reaching the end; remember, unknown to Hansel and Gretel but known to you, the path only continues either East or South, and there is only one path and no dead-ends • function crumbsLeft which takes, as a parameter, the number of breadcrumbs left (which may be negative if the path is longer than the number of breadcrumbs) and prints that there were not enough breadcrumbs, just enough breadcrumbs, or the actual amount of breadcrumbs left For example, given the following forest map: forestPath = [[' ',' ',' ','X','X'],\ ['X','X',' ',' ','X'],\ ['X','X','X',' ','X'],\ [' ','X','X',' ',' '],\ [' ','X','X','X',' '],\ [' ',' ','X','X',' '],\ [' ',' ','X','X','E']] If the number of breadcrumbs given is 12, sample output would be: Enter number of breadcrumbs: 12 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', '*', 'X'], [' ', 'X', 'X', '*', '*'], [' ', 'X', 'X', 'X', '*'], [' ', ' ', 'X', 'X', '*'], [' ', ' ', 'X', 'X', 'E']] 2 breadcrumb(s) are left If the number of breadcrumbs given is 5, sample output would be: Enter number of breadcrumbs: 5 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', ' ', 'X'], [' ', 'X', 'X', ' ', ' '], [' ', 'X', 'X', 'X', ' '], [' ', ' ', 'X', 'X', ' '], [' ', ' ', 'X', 'X', 'E']] Not enough breadcrumbs for the trip. If the number of breadcrumbs given is 10, sample output would be: Enter number of breadcrumbs: 10 [['*', '*', '*', 'X', 'X'], ['X', 'X', '*', '*', 'X'], ['X', 'X', 'X', '*', 'X'], [' ', 'X', 'X', '*', '*'], [' ', 'X', 'X', 'X', '*'], [' ', ' ', 'X', 'X', '*'], [' ', ' ', 'X', 'X', 'E']] Phew, just enough breadcrumbs for the trip.

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education