Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code using Python Fire engine inspection checklist Fire trucks require regular inspection. The fire department is compiling a new inspection checklist. A fire truck

image text in transcribed

image text in transcribed

Please code using Python

Fire engine inspection checklist Fire trucks require regular inspection. The fire department is compiling a new inspection checklist. A fire truck has many components and for some of them the order of inspection is important. For example, certain valves must be checked before the pump, but the ladder can be anywhere in the checklist. Write a function checklist (conditions) that takes a description of which component must be checked before which, and returns, if possible, a checklist (ordering of components) such that all the given conditions are satisfied Details of input and output The input is a string. The first line starts with the character D, followed by space, followed by a natural number n specifying the number of components. The components are numbered 0 to n-1. The remaining lines (if any) are of the form a b which means that component a must be checked before component If there is a solution, the function must return a list of length n of components in a valid order from left to right. If there are multiple solutions any one of them is acceptable. If there is no solution, the function must return None. For example Test Result conditions" D 2 0 1 print(checklist (conditions)) conditions D 3 1 2 0 2 True print (checklist(conditions) in [[0, 1, 2], [1, 0, 2]]) Fire engine inspection checklist Fire trucks require regular inspection. The fire department is compiling a new inspection checklist. A fire truck has many components and for some of them the order of inspection is important. For example, certain valves must be checked before the pump, but the ladder can be anywhere in the checklist. Write a function checklist (conditions) that takes a description of which component must be checked before which, and returns, if possible, a checklist (ordering of components) such that all the given conditions are satisfied Details of input and output The input is a string. The first line starts with the character D, followed by space, followed by a natural number n specifying the number of components. The components are numbered 0 to n-1. The remaining lines (if any) are of the form a b which means that component a must be checked before component If there is a solution, the function must return a list of length n of components in a valid order from left to right. If there are multiple solutions any one of them is acceptable. If there is no solution, the function must return None. For example Test Result conditions" D 2 0 1 print(checklist (conditions)) conditions D 3 1 2 0 2 True print (checklist(conditions) in [[0, 1, 2], [1, 0, 2]])

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

More Books

Students also viewed these Databases questions

Question

Active listening is hard work. True False

Answered: 1 week ago

Question

Turtle phyton trinangle inside rectangle

Answered: 1 week ago