Instructions Write a Python program to solve the following problem. Your solution should include a readme.md file (which

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Instructions Write a Python program to solve the following problem. Your solution should include a readme.md file (which

Post by answerhappygod »

Instructions Write A Python Program To Solve The Following Problem Your Solution Should Include A Readme Md File Which 1
Instructions Write A Python Program To Solve The Following Problem Your Solution Should Include A Readme Md File Which 1 (105.56 KiB) Viewed 449 times
Text From Image:
The data are stored in a file named routes.txt, with each line
starting with a route number, followed by a comma (,), followed by
the ratio of happy customers to unhappy customers for that route.
Any line that does not meet this format exactly should be seen as
an error. Further, each route should only be listed in the file
once. A repeated route should also be seen as an error.

Your task is to read in the data from routes.txt
and, if there are no errors reading the data, ask the user how many
extra routes they can put an extra bus on (call this n). Your
program should guarantee that n is not greater than the total
number of routes listed in routes.txt - otherwise you should prompt
the user to enter a new value for n. Your program should then
output the top n routes that would most benefit from having an
extra bus.

To extract the data from routes.txt, your program should have a
function named read_route_data that takes a single parameter that
is the name of the file to read the data from. It should return a
list of dictionaries, with each dictionary including the keys
route_number and happy_ratio if the data read from routes.txt is
valid. Otherwise, if there are any errors reading data from the
file, this function should raise an exception.

Your main program should call this function and handle any
exceptions. To determine which routes would most benefit from an
extra bus, you should sort the route data based on the ratio of
happy customers to unhappy customers for that route. Routes should
generally be ordered from the lowest to highest value of this
ratio, though routes with a ratio of 0 should be placed at the end
of the list (this represents a route where there were 0 unhappy
customers, so an extra bus should only be added if there are any
spare after busses have been added to other routes). The first
route in this sorted order is then the one that would most benefit
from an additional bus.

To sort the data returned from read_route_data, you should have a
function named sort_route_data that takes a single parameter that
is a list of dictionaries. This function should return a list of
dictionaries sorted, as described above, by the happy_ratio key in
the dictionaries. Your main program should use a value returned
from this function to determine the n routes that would most
benefit from extra busses. Note: Your solution must include the two
functions specified above, and can include other functions if you
would like. There is no requirement to use any particular sorting
algorithm for this assignment. Any algorithm that gives the correct
result can be used.
Instructions Write a Python program to solve the following problem. Your solution should include a readme.md file (which includes details of how to run your assignment) and your Python program in a file named routes.py, and be submitted as a single. tgz file named pt2.tgz. You should ensure your solution works using the Python 3 interpreter on turing. Problem Thanks to your busstop.py program, Codetown's mayor has decided that changing school hours is not feasible at this time. However, the data has shown that some bus routes are overcrowded, and could benefit from adding extra busses. The mayor has again called on you to develop a program to determine which routes would most benefit from additional busses. The data are stored in a file named routes.txt, with each line starting with a route number, followed by a comma (,), followed by the ratio of happy customers to unhappy customers for that route. Any line that does not meet this format exactly should be seen as an error. Further, each route should only be listed in the file once. A repeated route should also be seen as an error. Your task is to read in the data from routes.txt and, if there are no errors reading the data, ask the user how many extra routes they can put an extra bus on (call this n). Your program should guarantee that n is not greater than the total number of routes listed in routes.txt - otherwise you should prompt the user to enter a new value for n. Your program should then output the top n routes that would most benefit from having an extra bus. To extract the data from routes.txt, your program should have a function named read_route_data that takes a single parameter that is the name of the file to read the data from. It should return a list of dictionaries, with each dictionary including the keys route_number and happy_ratio if the data read from routes.txt is valid. Otherwise, if there are any errors reading data from the file, this function should raise an exception. Your main ogra should call this function and handle any exceptions. To determine which routes would most benefit from an extra bus, you should sort the route data based on the ratio of happy customers to unhappy customers for that route. Routes should generally be ordered from the lowest to highest value of this ratio, though routes with a ratio of O should be placed at the end of the list (this represents a route where there were 0 unhappy customers, so an extra bus should only be added if there are any spare after busses have been added to other routes). The first route in this sorted order is then the one that would most benefit from an additional bus. To sort the data returned from read_route_data, you should have a function named sort_route_data that takes a single parameter that is a list of dictionaries. This function should return a list of dictionaries sorted, as described above, by the happy_ratio key in the dictionaries. Your main program should use a value returned from this function to determine the n routes that would most benefit from extra busses. Note: Your solution must include the two functions specified above, and can include other functions if you would like. There is no requirement to use any particular sorting algorithm for this assignment. Any algorithm that gives the correct result can be used. Example Interaction Given the following contents in routes.txt: 123,4 321,0 567,8.753 459,0.00
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply