Part 1: Concise output In this section, we will modify the program in Lab 1 to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Part 1: Concise output In this section, we will modify the program in Lab 1 to produce more concise output. In CSV (comma-separated values) format, values are separated by commas (hence the name). Modify your program to output the results in CSV format. You should have one line with header labels and one line with the corresponding values. Here is the output from a run of the desired program: Fuel, Velocity, Duration, Fuel cost, Losses, Value lost 10000,953.1017980432493,910.768983268842,10000000, 109292277.99226104, 119292277.99226104 CSV formatted data is meant to be used by programs on the computer (e.g., you can input CSV formatted data into Excel as a spreadsheet), it is not meant to be read by users. As such, there is no need to format (e.g., limit the number of displayed decimal places) or align the values before printing them. There is also no need to include units (e.g., m/s, USD). We will be learning how to create .csv files formatted in this manner soon, but for now, we will just print out the CSV formatted data to the terminal. Part 2: User-friendly output Since CSV is not very user-friendly, we will now write some additional code to output easily human-readable tables of results (be sure not to delete your code that outputs in CSV! We will still be using that in later parts of the project). For more user-friendly output, you will use Python's print and format, as discussed in lecture. For each value (Fuel, Velocity, Duration, etc.), you will need to figure out how many characters will be needed to display each value in order to determine how wide each column of our table needs to be. In the following example, representing the total value lost (119,292,278) requires 11 characters (nine digits and two commas). You will need to experiment with different amounts of fuel to determine how large each value can get and set the appropriate width value in format. Do not forget to account for units (e.g., m/s, USD) in determining your column sizes! Here is the output from a run of the desired program: -Desired output when user enters fuel = 100,000: Fuel Duration Velocity Fuel cost 100,000 kg 6,931.47 m/s 125.2 days 100,000,000.00 USD Losses Value lost 15,028,073.34 USD 115,028,073.34 USD -Desired output when user enters fuel = 1: Fuel 1 kg Velocity 0.10 m/s 8680599.0 days Duration Fuel cost Losses Value lost 1,000.00 USD 1,041,671,874,984.50 USD 1,041,671,875,984.50 USD Part 3: Choosing between the two output formats Modify your program so that it asks the user whether they would like to output in human-readable or CSV format. You should present the user with both of these options and allow them to select one or the other, the print out in the corresponding format. Here is the output from several runs of the desired program: 1. If user enters 10,000 for fuel and selects 1: Enter value for fuel in kilograms [0-100,000kg]: 10000 How would you like to format the output? 1: CSV 2: Human-readable Enter 1 or 2: 1 Fuel, Velocity, Duration, Fuel cost, Losses, Value lost 10000,953.1017980432493,910.768983268842,10000000, 109292277.99226104, 119292277.99226104 2. If user enters 10,000 for fuel and selects 2: Enter value for fuel in kilograms [0-100,000kg]: 10000 How would you like to format the output? 1: CSV 2: Human-readable Enter 1 or 2: 2 Fuel Velocity Duration Fuel cost Losses Value lost. 10,000 kg 953.10 m/s 910.8 days 10,000,000.00 USD 109,292,277.99 USD 119,292,277.99 USD Part 1: Concise output In this section, we will modify the program in Lab 1 to produce more concise output. In CSV (comma-separated values) format, values are separated by commas (hence the name). Modify your program to output the results in CSV format. You should have one line with header labels and one line with the corresponding values. Here is the output from a run of the desired program: Fuel, Velocity, Duration, Fuel cost, Losses, Value lost 10000,953.1017980432493,910.768983268842,10000000, 109292277.99226104, 119292277.99226104 CSV formatted data is meant to be used by programs on the computer (e.g., you can input CSV formatted data into Excel as a spreadsheet), it is not meant to be read by users. As such, there is no need to format (e.g., limit the number of displayed decimal places) or align the values before printing them. There is also no need to include units (e.g., m/s, USD). We will be learning how to create .csv files formatted in this manner soon, but for now, we will just print out the CSV formatted data to the terminal. Part 2: User-friendly output Since CSV is not very user-friendly, we will now write some additional code to output easily human-readable tables of results (be sure not to delete your code that outputs in CSV! We will still be using that in later parts of the project). For more user-friendly output, you will use Python's print and format, as discussed in lecture. For each value (Fuel, Velocity, Duration, etc.), you will need to figure out how many characters will be needed to display each value in order to determine how wide each column of our table needs to be. In the following example, representing the total value lost (119,292,278) requires 11 characters (nine digits and two commas). You will need to experiment with different amounts of fuel to determine how large each value can get and set the appropriate width value in format. Do not forget to account for units (e.g., m/s, USD) in determining your column sizes! Here is the output from a run of the desired program: -Desired output when user enters fuel = 100,000: Fuel Duration Velocity Fuel cost 100,000 kg 6,931.47 m/s 125.2 days 100,000,000.00 USD Losses Value lost 15,028,073.34 USD 115,028,073.34 USD -Desired output when user enters fuel = 1: Fuel 1 kg Velocity 0.10 m/s 8680599.0 days Duration Fuel cost Losses Value lost 1,000.00 USD 1,041,671,874,984.50 USD 1,041,671,875,984.50 USD Part 3: Choosing between the two output formats Modify your program so that it asks the user whether they would like to output in human-readable or CSV format. You should present the user with both of these options and allow them to select one or the other, the print out in the corresponding format. Here is the output from several runs of the desired program: 1. If user enters 10,000 for fuel and selects 1: Enter value for fuel in kilograms [0-100,000kg]: 10000 How would you like to format the output? 1: CSV 2: Human-readable Enter 1 or 2: 1 Fuel, Velocity, Duration, Fuel cost, Losses, Value lost 10000,953.1017980432493,910.768983268842,10000000, 109292277.99226104, 119292277.99226104 2. If user enters 10,000 for fuel and selects 2: Enter value for fuel in kilograms [0-100,000kg]: 10000 How would you like to format the output? 1: CSV 2: Human-readable Enter 1 or 2: 2 Fuel Velocity Duration Fuel cost Losses Value lost. 10,000 kg 953.10 m/s 910.8 days 10,000,000.00 USD 109,292,277.99 USD 119,292,277.99 USD
Expert Answer:
Answer rating: 100% (QA)
To accomplish the three parts stated in the description I will provide you with the Python code below The following program includes the modified vers... View the full answer
Related Book For
Probability and Random Processes With Applications to Signal Processing and Communications
ISBN: 978-0123869814
2nd edition
Authors: Scott Miller, Donald Childers
Posted Date:
Students also viewed these programming questions
-
Image transcription text Module 5 Discussion A' Instructions: This discussion will be completed in two parts, and will give you an opportunity to reect upon this week's content and to interact with...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Delmott sells a snowboard, Xpert that is popular with snowboard enthusiasts. Below is information relating to Delmotts purchases of Xpert snowboards during September. During the same month, 102 Xpert...
-
A stockbroker advises a client to "buy preferred stock. . . . With that type of stock, . . . [you] will never have to worry about losing the dividends." Is the broker right?
-
In Exercise 9-15, calculate the P-value if the observed statistic is (a) x = 180 (b) x = 190 (c) x = 170
-
Meghann Patrick is a former employee of Altria Group Distribution Company. After her employment was terminated, Patrick sued Altria and a supervisor at Altria, alleging employment-related claims...
-
Flow in a slit with uniform cross flow (Fig. 3B.16). A fluid flows in the positive x-direction through a long flat duct of length L, width W, and thickness B, where L > > W >> B. The duct has porous...
-
An US firm agrees to sells a Yen Bond at 4% to a Japanese firm and purchases an USD bond at 8% from the Japanese firm. Yen interest rate: 1% (continuous compounded) USD interest rate: 2% (continuous...
-
Please put true or false with explanation. Case 5: Achaian, Inc. v. LeemonFamily LLC, 25 A. 3d 800 (Del. Ch. Ct. 2011) (Mallor 16 th Ed. p. 1067, case 6). Omniglow, LLC, a Delaware limited liability...
-
Laila has a $150,000 3-year, term deposit and a $75,000 1-year, GIC sitting in an account at Lincoln Trust & Saving Company. This financial institution is a member institution of the Canada Deposit...
-
Today you observe the following NYMEX Natural Gas ("NG") futures prices, and discount factors associated with each payment date: 2.551 0.9962 2.713 0.9918 2.95 0.9872 3.153 0.9827 3.19 0.9781 3.157...
-
GE's beginning and ending LIFO inventories were: 10,427 and 9,203 , respectively . GE had a pre-tax liquidation gain of 507. Note that inventory increased despite the liquidation, because GE uses...
-
Blake's Manufacturing Company provides the following ABC costing information: Activities Total Costs Activity-cost drivers Account inquiry ...
-
An accounting information system (AIS) is a subsystem of the overall management information system that provides information to an organization in the right format, size, time frame, and within a...
-
A company reported net income of $78,000 and had 15,000 common shares outstanding throughout the current year. At year-end, the price per share of the company's stock was $49.40. What is the...
-
Subtract the polynomials. (-x+x-5) - (x-x + 5)
-
Two zero- mean discrete- time random processes, X [n] and Y [n], are statistically independent. Let a new random process be Z [n] = X [n] + Y [n]. Let the autocorrelation functions for X [n] and X...
-
A known deterministic signal, s (t), plus colored (not white) noise; N (t), with a PSD of SNN (f) is input to a filter. Derive the form of the filter that maximizes the SNR at the output of the...
-
Cards are drawn from a standard 52- card deck. After each card is drawn, it is put back in the deck and the cards are reshuffled so that each card drawn is independent of all others. Let N be the...
-
Which mechanism of bacterial genetic transfer does not require recombination with the bacterial chromosome?
-
Explain why small deletions and duplications are less likely than large ones to have a detrimental effect on an individuals phenotype. If a small deletion within a single chromosome happens to have a...
-
Explain why inversions and reciprocal translocations do not usually cause a phenotypic effect. Then explain how they can do so in certain cases.
Study smarter with the SolutionInn App