Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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)
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
Step by Step Solution
★★★★★
3.39 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
The function should receive a string as a parameter that contains the prompt to display to the user ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started