Question: I need help writing the second function. I am not getting the correct output when I write the second fuction. Here is what I have
I need help writing the second function. I am not getting the correct output when I write the second fuction. Here is what I have def calc_boarded(boarding, departing, current): #First function, this one works correctly# return current + boarding - min(departing, current) def run_sim(stops, boarding_rate, exiting_rate, passengers): stop_count = 0 while stop_count boarding = boarding_rate departing = min(passengers, exiting_rate) passengers = calc_boarded(boarding, departing, passengers) print(f"Stop {stop_count}: {boarding} boarding, {departing} exiting, {passengers} on the bus") stop_count += 1 print(f"Final Stop: {passengers} on the bus")
calc_boarded (boarding, departing, current) - Calculates and returns the new number of items in a queue based on the number of items arriving at the queue, the number of items departing the queue, and the number of items that are already in the queue. Note that this is a general count-based implementation of the FIFO queue described above. Note that this function does not output (print) the computed value! This only performs the essential computation common to any simple count-based queue, nothing about bus lines. Here are some example return values calculated by the calc_boarded function: calc_boarded (20, 10, 15) returns 25 calc_boarded (20, 10, 5) returns 20 # Note, only 5 can exit despite the exit rate calc_boarded (5, 10, 15) returns 10 run_sim (stops, board_rate, exit_rate, starting passengers) - Executes the simulation, calculating and outputting the number of passengers riding, boarding, and exiting the bus line for each stop. The simulation stops after outputting the line that represents the final destination. This function should implement the design you documented in your sim_design.pdf (above). Here is an example output generated by run_sim (10, 15, 10, 5): 1 5 15 5 2 15 10 3 10 4 5 69 7 8 9 20 25 30 35 40 45 50 15 15 15 15 15 15 15 15 99 10 10 10 10 10 10 10 55 55 Note that you need to output the data in the tabular format as shown in the example output above. Consider using the string format method we've learned to generate the formatted output.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
