Question

In: Computer Science

This problem requires you to prompt the user for some information, and apply simple arithmetic operation...

This problem requires you to prompt the user for some information, and apply simple arithmetic operation to generate an output.

We all know that driving is expensive. So let's write a program to observe this.

  • Your job is to prompt the driver for
    • miles per gallon and
    • gas price (in dollars) per gallon

You should prompt the user with the words: Enter miles per gallon: at which time the users enters a number, and then Enter the gas price:at which time the user enters the second number. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts.

Both inputs should be read as  float data type , and your program will output the gas cost for 10 miles, 50 miles, and 400 miles. Due to the way floating point numbers are internally stored, there can be some discrepancies with the precision of calculations depending on the order things are done. To prevent this from causing your submission to be marked incorrect, please calculate the cost in the following order:  The miles increment (10, 50, or 400) multiplied by 1.0/miles per gallon multiplied by the gas price.

Example: If the input is:

Enter miles per gallon:20.0
Enter the gas price:3.1599

Then the output is:

1.57995 7.89975 63.198

Note: Real per-mile cost would also include maintenance and depreciation.

Someone please help! Can't get it right! (This is python)

Solutions

Expert Solution

PROGRAM:

miles_per_gallon=float(input("Enter miles per gallon:"))

# [Get the miles per gallon as input from the user as floating point number]

gas_price=float(input("Enter the gas price:"))

#[ Similarly get the gas price from the user as floating point number]
print(10*1.0/miles_per_gallon*gas_price,end=' ')

# [The gas cost for 10 miles is given by 10 multiplied with 1.0 divided by miles per gallon which is then multiplied with the gas price( as given in the question). end=' ' is used to prevent the program from going to the next line and providing only a space so that all the 3 outputs are displayed in the same line separated only by spaces ]
print(50*1.0/miles_per_gallon*gas_price,end=' ')

#[Similarly print the gas cost for 50 miles and 400 miles using the formula given]
print(400*1.0/miles_per_gallon*gas_price,end=' ')

OUTPUT:


Related Solutions

write a script named compute.sh that is used to do simple arithmetic for the user. There...
write a script named compute.sh that is used to do simple arithmetic for the user. There should be no command line arguments. Instead, all values from the user should be prompted for and read in to the script using the read command. Specifically, you need to ask the user for two integers and an operation string. The operation should be "add", "sub", "mul", "div", or "exp", for addition, subtraction, multiplication, division, and exponentiation, respectively. Your script should take the two...
Problem 4: Reading Binary You must write a program that willcontinuously prompt the user for...
Problem 4: Reading Binary You must write a program that will continuously prompt the user for a string representing a binary number. Then you should validate whether that string is valid binary number, and in case it is you must print the corresponding number in decimal base. Otherwise, you should state that the input string is not a valid binary number. Use the string “QUIT” to end the program. You should be aware that the input string may contain noise...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a C program that repeatedly prompts the user for input at a simple prompt (see...
Write a C program that repeatedly prompts the user for input at a simple prompt (see the sample output below for details). Your program should parse the input and provide output that describes the input specified. To best explain, here's some sample output: ibrahim@ibrahim-latech:~$ ./prog1 $ ls -a -l -h Line read: ls -a -l -h Token(s): ls -a -l -h 4 token(s) read $ ls -alh Line read: ls -alh Token(s): ls -a -l -h 2 token(s) read $...
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
in java Create simple number guessing game as follows. First, prompt the user to enter a...
in java Create simple number guessing game as follows. First, prompt the user to enter a min and max value. In your code, declare and assign a variable with a random integer in this range (inclusive). Then, ask the user to guess the number. Input the user's guess. And at the end output "Correct!" if the user's guess was right on spot, or "Sorry, the answer is not corrcet.” The number I was looking for was xxx. Replace xxx with...
Create a program that will prompt for user information for a Web site. Use a structure...
Create a program that will prompt for user information for a Web site. Use a structure to store the data. The structure will need to include the following items: First Name - string Last Name - string Full Name - string Birth Date   - int (assume format yyyymmdd) IsLeasingAutomobile - bool yearlySalary - float Create a single structure from the items listed above. Prompt for all items except "Full Name" and load the input directly into a variable based on...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
In this problem you will apply the utility maximization framework to try to understand some of...
In this problem you will apply the utility maximization framework to try to understand some of the effects of the current banking crisis on consumers wellbeing. Take a two period model in which consumers utility function is U(C1,C2)=C1C2 where C1 is consumption in period 1 and C2 consumption in period 2, both retrieved in cash. The consumer is free to borrow or save in period one as the interest rate r, through the banking system. a) Write the consumer's inter-temporal...
Simulate a problem with undo. You will need to be connected as user SYSTEM or some...
Simulate a problem with undo. You will need to be connected as user SYSTEM or some other user to whom you have granted the DBA role. . Create an undo tablespace with a single datafile of only 200 KB. Do not set the file to autoextend. . Set the database to use this small undo tablespace. Confirm that an undo segment has been created in this tablespace and that it is online by querying the views DBA_ROLLBACK_SEGS and V$ROLLSTAT. Why...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT