Input Validation The idea of input validation means that we want to be sure that the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Input Validation The idea of input validation means that we want to be sure that the input the user provides is actually valid for use in our program. If it is, we know that we can use it safely in our computations. If it isn't, we cannot use it and will need to ask the user to re-enter the input. In general, valid input is user-supplied data that is of the correct type and that is within an acceptable range of values. For Part 2 of this project, you will implement a more robust version of the get_int function you implemented in Project 1. You will also implement an additional function named get_ints. This new function will require users to input several integers and return them in a list. Both of these functions should be implemented in a csc111_input module. The interface of your functions should look like this: get_int (prompt, low, high) returns an integer within low and high get_ints (number, prompt, low, high) returns a list of number integers within low and high Figure 2 below shows a flowchart for the implementation of the get_int function. Your first task will be to implement this function by following the flowchart. Then, you will need to use this function as part of your get_ints function. Start Display Prompt, Collect Input, and Store it to a Variable Convert Value to an int Value >= lower bound True Value Core Simulation As described in Part 1, the core simulation is the hardest working part of the program. You implemented a basic level of this functionality in your calc_boarded function. For Part 2, you will expand on the run_sim function to create a more robust and flexible simulation. We will describe additional implementation details in the Implementation section of this document. Your run_sim function header should be modified to look like this: run_sim (iterations, board_rates, exit_rates) The design of this function for Part 2 incorporates the functionality described in Part 1 along with a few additional features: Passengers no longer must exit the bus at the end of the number of stops. Consider the example bus line in Figure 1, which begins to loop back to the initial starting location. Instead of stopping at the last stop. the simulation will run through N iterations, stopping at each stop. Once the bus reaches the last stop, it will return to the starting location with a new set of passengers currently riding the bus. We no longer assume passengers were boarding and departing the bus line at an equal rate across stops. Instead, we will ask the user to provide the boarding rates and exit rates for each stop as two lists. board_rates is a list of boarding rates at each stop, and exit_rates is a list of exit rates at each stop. Note as well, this run_sim function does not have a starting_passengers parameter. You can instead assume at iteration 0 there are 0 starting passengers. When the simulation loops back to the starting location however, this does not reset to 0. Here is an example output generated by run_sim (10, [8, 10, 8], [5, 10, 10]): 1 0 8 0 2 3 4 5 LO 6 8 10 00 10 8 5 11 10 11 10 7 9 5 8 12 10 9 12 10 10 10 8 5 Notice that 10 means run_sim will simulate the bus line 10 stops. [8, 10, 8] means the list of the boarding rates at each bus stop, and [5, 10, 10] means the list of the exit rates at each bus stop. This implies there are in total 3 bus stops in the simulation. Even though there are 3 bus stops on this example bus line, the simulation is able to loop back through and repeat the process over and over again until the number of iterations has been exhausted. Overall Program 00 00 10 8 00 8 10 8 00 00 8 10 8 00 For context, we again describe, from the user's perspective, how the final program will work. Note that this description is expanded from the one given in Part 1. The simulation should prompt the user to enter the number of stops along the bus line's route. The simulation should then prompt the user to enter the board rates for each stop. The simulation should then prompt the user to enter the exit rates for each stop. o Note the board and exit rate lists must be the same size. Finally, the simulation should execute and display a tabular output similar to Part 1. The only difference is that the board and exit rates should reflect the modified inputs for Part 2 and should also include headers for each column. Your program will use your updated csc111_input module. Specifically, you will update the following two functions: get_int (prompt, low, high) - Uses the string stored in the prompt to ask the user for input. If the input is valid (between low and high), the int value is returned. If not, the function will display an appropriate error message to the user and prompt for input again until the user enters a valid integer value. If the user enters anything that cannot be converted to an int, a ValueError will be generated. get_ints (number, prompt, low, high) - Utilizes the get_int function displayed above to collect a list of valid integers one by one. You will need to pass the prompt, low, and high parameters to the get_int function. The parameter number represents the total number of integers the user wants to collect. The function will return a list of collected valid inputs. You need to update your cscll1_input.py created in Project 1 Part 1 with the two functions above. Of course, to use these functions, you will need to import your csc111_input module into your main program script. Main Program Implementation You will implement your simulation program in a file named p2p2_sim.py. Your program must implement and use the following functions: calc_boarded (boarding, departing, current) - This function should be an exact copy of your Project 2 Part 1 implementation. run_sim (iterations, board_rates, exit_rates) - Executes the simulation, calculating and outputting the stop by stop volumes of passengers boarding, departing, and riding the bus line. The arguments represent the total number of iterations the simulation should run, a list of boarding rates at each stop, and a list of exit rates at each stop. The simulation stops after outputting N stops, where N is equal to the number of iterations. The total width of the tabular output from this function shall not exceed a width of 75 character columns on a terminal/command prompt display. print_welcome () - This function neatly prints a welcome message. Your welcome message must include your name, unity ID, and lab section number. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 20 lines. print_goodbye () - This function neatly prints a "goodbye" message to the user. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 5 lines. main () This function will contain your main program loop similar to the output below. The execution of this function must be controlled by the if _name___ == '__main__': statement provided in the course template. You need to call get_int and get_ints functions to collect the number of stops, boarding rate for each stop, exit rate for each stop and the number of iterations to simulate in the main function. Please assume the valid range of inputs for the number of stops is 3-8 (both inclusive), for the board_rate and exit_rate is 0-50 (both inclusive), and for the number of iterations is 10-20 (both inclusive). For reference purposes, a sample run output is provided below, where the text in red is user input. Note that the exact numbers will vary based on the inputs you select. However, this output can serve as a guide for formatting your own program's output. Welcome to my Bus Line Simulator. This program simulates the passenger flow on a single bus route. The simulation will continue to run for a specified number of iterations, showing the number of passengers currently riding, boarding, and departing the bus at each stop. Enter the number of stops on the bus line's route: 3 Enter the boarding rate for each stop (one at a time): 8 Enter the boarding rate for each stop (one at a time): 10 Enter the boarding rate for each stop (one at a time): 8 Enter the exit rate for each stop (one at a time): 5 Enter the exit rate for each stop (one at a time): 10 Enter the exit rate for each stop (one at a time): 10 Enter the number of iterations to simulate: 10 Iterations Current 1 1.000 WNP 2 3 5 6 7 8 9 10 00 O 8 10 8 11 11 9 12 12 10 PRR Boarding Departing 8 10 00 00 8 8 10 00 00 00 00 10 8 10 5 OPPO 00 10 10 5 10 GPP 00 10 5 Thank you for using my bus line simulation program. Input Validation The idea of input validation means that we want to be sure that the input the user provides is actually valid for use in our program. If it is, we know that we can use it safely in our computations. If it isn't, we cannot use it and will need to ask the user to re-enter the input. In general, valid input is user-supplied data that is of the correct type and that is within an acceptable range of values. For Part 2 of this project, you will implement a more robust version of the get_int function you implemented in Project 1. You will also implement an additional function named get_ints. This new function will require users to input several integers and return them in a list. Both of these functions should be implemented in a csc111_input module. The interface of your functions should look like this: get_int (prompt, low, high) returns an integer within low and high get_ints (number, prompt, low, high) returns a list of number integers within low and high Figure 2 below shows a flowchart for the implementation of the get_int function. Your first task will be to implement this function by following the flowchart. Then, you will need to use this function as part of your get_ints function. Start Display Prompt, Collect Input, and Store it to a Variable Convert Value to an int Value >= lower bound True Value Core Simulation As described in Part 1, the core simulation is the hardest working part of the program. You implemented a basic level of this functionality in your calc_boarded function. For Part 2, you will expand on the run_sim function to create a more robust and flexible simulation. We will describe additional implementation details in the Implementation section of this document. Your run_sim function header should be modified to look like this: run_sim (iterations, board_rates, exit_rates) The design of this function for Part 2 incorporates the functionality described in Part 1 along with a few additional features: Passengers no longer must exit the bus at the end of the number of stops. Consider the example bus line in Figure 1, which begins to loop back to the initial starting location. Instead of stopping at the last stop. the simulation will run through N iterations, stopping at each stop. Once the bus reaches the last stop, it will return to the starting location with a new set of passengers currently riding the bus. We no longer assume passengers were boarding and departing the bus line at an equal rate across stops. Instead, we will ask the user to provide the boarding rates and exit rates for each stop as two lists. board_rates is a list of boarding rates at each stop, and exit_rates is a list of exit rates at each stop. Note as well, this run_sim function does not have a starting_passengers parameter. You can instead assume at iteration 0 there are 0 starting passengers. When the simulation loops back to the starting location however, this does not reset to 0. Here is an example output generated by run_sim (10, [8, 10, 8], [5, 10, 10]): 1 0 8 0 2 3 4 5 LO 6 8 10 00 10 8 5 11 10 11 10 7 9 5 8 12 10 9 12 10 10 10 8 5 Notice that 10 means run_sim will simulate the bus line 10 stops. [8, 10, 8] means the list of the boarding rates at each bus stop, and [5, 10, 10] means the list of the exit rates at each bus stop. This implies there are in total 3 bus stops in the simulation. Even though there are 3 bus stops on this example bus line, the simulation is able to loop back through and repeat the process over and over again until the number of iterations has been exhausted. Overall Program 00 00 10 8 00 8 10 8 00 00 8 10 8 00 For context, we again describe, from the user's perspective, how the final program will work. Note that this description is expanded from the one given in Part 1. The simulation should prompt the user to enter the number of stops along the bus line's route. The simulation should then prompt the user to enter the board rates for each stop. The simulation should then prompt the user to enter the exit rates for each stop. o Note the board and exit rate lists must be the same size. Finally, the simulation should execute and display a tabular output similar to Part 1. The only difference is that the board and exit rates should reflect the modified inputs for Part 2 and should also include headers for each column. Your program will use your updated csc111_input module. Specifically, you will update the following two functions: get_int (prompt, low, high) - Uses the string stored in the prompt to ask the user for input. If the input is valid (between low and high), the int value is returned. If not, the function will display an appropriate error message to the user and prompt for input again until the user enters a valid integer value. If the user enters anything that cannot be converted to an int, a ValueError will be generated. get_ints (number, prompt, low, high) - Utilizes the get_int function displayed above to collect a list of valid integers one by one. You will need to pass the prompt, low, and high parameters to the get_int function. The parameter number represents the total number of integers the user wants to collect. The function will return a list of collected valid inputs. You need to update your cscll1_input.py created in Project 1 Part 1 with the two functions above. Of course, to use these functions, you will need to import your csc111_input module into your main program script. Main Program Implementation You will implement your simulation program in a file named p2p2_sim.py. Your program must implement and use the following functions: calc_boarded (boarding, departing, current) - This function should be an exact copy of your Project 2 Part 1 implementation. run_sim (iterations, board_rates, exit_rates) - Executes the simulation, calculating and outputting the stop by stop volumes of passengers boarding, departing, and riding the bus line. The arguments represent the total number of iterations the simulation should run, a list of boarding rates at each stop, and a list of exit rates at each stop. The simulation stops after outputting N stops, where N is equal to the number of iterations. The total width of the tabular output from this function shall not exceed a width of 75 character columns on a terminal/command prompt display. print_welcome () - This function neatly prints a welcome message. Your welcome message must include your name, unity ID, and lab section number. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 20 lines. print_goodbye () - This function neatly prints a "goodbye" message to the user. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 5 lines. main () This function will contain your main program loop similar to the output below. The execution of this function must be controlled by the if _name___ == '__main__': statement provided in the course template. You need to call get_int and get_ints functions to collect the number of stops, boarding rate for each stop, exit rate for each stop and the number of iterations to simulate in the main function. Please assume the valid range of inputs for the number of stops is 3-8 (both inclusive), for the board_rate and exit_rate is 0-50 (both inclusive), and for the number of iterations is 10-20 (both inclusive). For reference purposes, a sample run output is provided below, where the text in red is user input. Note that the exact numbers will vary based on the inputs you select. However, this output can serve as a guide for formatting your own program's output. Welcome to my Bus Line Simulator. This program simulates the passenger flow on a single bus route. The simulation will continue to run for a specified number of iterations, showing the number of passengers currently riding, boarding, and departing the bus at each stop. Enter the number of stops on the bus line's route: 3 Enter the boarding rate for each stop (one at a time): 8 Enter the boarding rate for each stop (one at a time): 10 Enter the boarding rate for each stop (one at a time): 8 Enter the exit rate for each stop (one at a time): 5 Enter the exit rate for each stop (one at a time): 10 Enter the exit rate for each stop (one at a time): 10 Enter the number of iterations to simulate: 10 Iterations Current 1 1.000 WNP 2 3 5 6 7 8 9 10 00 O 8 10 8 11 11 9 12 12 10 PRR Boarding Departing 8 10 00 00 8 8 10 00 00 00 00 10 8 10 5 OPPO 00 10 10 5 10 GPP 00 10 5 Thank you for using my bus line simulation program.
Expert Answer:
Related Book For
Managerial Accounting
ISBN: 978-1259024900
9th canadian edition
Authors: Ray Garrison, Theresa Libby, Alan Webb
Posted Date:
Students also viewed these programming questions
-
Microkernel operating systems aim to address perceived modularity and reliability issues in traditional "monolithic" operating systems. (i) Describe the typical architecture of a microkernel...
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
1. The two taxes paid on most purchases are the amount of each tax is % and and the % respectively. 2. Use the "10% + 5%" method of estimating total cost. Estimated Rounded Cost Item Cost 10% 5%...
-
Solve Problem 6.93 for a frame where h = 6 ft. PROBLEM 6.93 A 3-ft-diameter pipe is supported every 16 ft by a small frame like that shown. Knowing that the combined weight of the pipe and its...
-
S omeone is selling a 1 0 0 year $ 5 0 0 annuity for $ 1 0 , 0 0 0 . What discount rate are they using to determine the price?
-
The following are measurements of the total dissolved salts (TDS) and hardness index of 22 samples of water. (a) Calculate \(r\). (b) Find 95% confidence limits for \(ho\). TDS (ppm) Hardness Index...
-
Two triangular wave pulses are traveling toward each other on a stretched string as shown in Fig.1S.33. Each pulse is identical to the other and travels at 2.00 cm/s. The leading edges of the pulses...
-
1. Show the final B-tree after inserting 61, 62 and 63 into the following B-tree, where M=L=5. 26 41 66 87 246 8 18 35 38 48 51 54 57 72 78 83 9297 12222 86246 |10 26 35 38 28 36 39 30 37 40 42 49 50...
-
Pacific Cruise Lines is a defendant in litigation involving a swimming accident on one of its three cruise ships. Required: For each of the following scenarios, determine the appropriate way to...
-
A particular cellular phone company has collected data on a sample of its customers. The data file contains data on over 2,000 customers. Each row contains the activity of a particular customer for a...
-
Look up works on the concept of the Bottom of the Pyramid, which was introduced by Prahalad and Hart. What is this concept and how does it differ from Porter and Kramers philosophy of Creating Shared...
-
Jenkins Company made the following expenditures during 2019: a. Recompletion costs on well #560 of $100,000 for IDC and $80,000 for equipment. The well was recompleted at 15,000 feet, which was a new...
-
Boeings big-ticket exports. Cathay Pacific, the Hong Kongbased airline, purchases five Boeing Dreamliners in 2013 for $750 million. The U.S. Export-Import Bank provides a seven-year loan for the full...
-
The company is now positioning itself to take advantage of Romanias relatively low wages to use its Dacia plant as an export platform to neighboring East European countries such as Bulgaria, Belarus,...
-
When the Bengladeshi taka depreciates. The central bank of Bangladesh is contemplating a devaluation of its currencythe taka (BDT)from BDT 69 to BDT 100 = US$1: a. What would be the percentage...
-
Consider a two-stroke spark ignition cycle with a compression ratio of 8.8. If the cycle max temperature is 2519C and the temperature at the beginning of the compression phase is 70C, what must the...
-
In Exercises delete part of the domain so that the function that remains is one-to-one. Find the inverse function of the remaining function and give the domain of the inverse function. f(x) = 16x4 -3...
-
Many organizations focus their strategy on providing high-quality customer service and consequently place metrics concerning customer relationship management on their balanced scorecards. Consider...
-
A firm makes two products: frying pans and saucepans. Frying pans sell for $30 each and saucepans sell for $20 each. The variable cost of making a frying pan is $20, and the variable cost of making...
-
What is the difference between total manufacturing costs incurred and the cost of goods manufactured?
-
How does the estimated ending inventory impact the individual income tax return ending inventory, cost of goods sold, net profit, and net income? Find out by adding an additional column for 2015 and...
-
Input information from the SBA Personal Financial Statements given to Sharptop Bank into a spreadsheet. a. Separate personal items (e.g., residence) from business items (e.g., inventory). b....
-
If the tax return or insurance claim is misstated, did Greg Larsen commit some form of financial statement fraud?
Study smarter with the SolutionInn App