How do I get fix the code to make it input 3 values and get the correct output
-------------------------------------------------------------
12.20 LAB: Driving costs - functions

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:.2f}'.format(your_value))

Ex: If the input is:

20.0
3.1599

the output is:

1.58
7.90
63.20

Your program must define and call the following driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles.

Ex: If the function is called with:

50 20.0 3.1599

the function returns:

7.89975

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon)

Your program should call the function three times to determine the gas cost for 10 miles, 50 miles, and 400 miles.
---------------------------------------------------
I need help for this part
Ex: If the function is called with:

50 20.0 3.1599

how do I get it to input the three to get the output of 7.89975?
-------------------------------------
My code:

# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
return (driven_miles/miles_per_gallon) * dollars_per_gallon

if __name__ == '__main__':
# Type your code here.

# Miles per gallon from input
miles_per_gallon = float(input())

#Dollars per gallon from input
dollars_per_gallon = float(input())


# Display the results as output

print('{:.2f}'.format(driving_cost(10, miles_per_gallon,dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(50, miles_per_gallon,dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(400, miles_per_gallon,dollars_per_gallon)))

Answers

Answer 1

Answer:Change your logic to:

for (int i = 0; i < 4; i++) {

System.out.println("Please input a number between zero to 3");

// use input and don't advance the scanner every time

int input = sc.nextInt();

if (input == 0) {

System.out.println("You have selected " + right);

}

if (input == 1) {

System.out.println("You have selected " + left);

}

// so on and so forth

}

By using sc.nextInt() four times, you are looking for the next token of the input which isn't there. So fetch the input for each run of the for-loop and it will work as expected.

Explanation:


Related Questions

Given the following code, what logic would you need to include to print all even values stored within the array:

int[] myArray = {1,2,38,4,54,6,7,8,9,10};

for (int i = 0; i < myArray.length; i++) {
//your code goes here
}
NOTE: Your response should be just the missing logic--not the entire problem set.

Answers

The missing logic whigh would allow all the even numbers stored within the array to be printed is if(myArray[i]%2 == 0)

Even numbers are divisible by 2, and hence, will leave no remainder when divided by 2.

Using the modulo operator, each iterated value in the array should be checked if it has a remainder of 0, when divided by 2.

Hence, if the remainder is 0, then the value is even and the value should be printed.

Learn more : https://brainly.com/question/17330574

Write a program that prompt the user to enter a bank balance. The balance entered by the user is read into a variable named balance. The program then prompts the user to enter the amount to be deposited. The amount entered by the user is read into a variable named deposit. The program that calculates the new balance, which is the present balance plus the deposit. The program then displays the new balance.

Answers

Answer:

ertyuiopoijuhgfdsa hiyoufun tresdfghytrefgytredfg

Explanation:

look for the words

Other Questions
Luisa buys a plane ticket that has an original price of $\$240$ . She uses a coupon code to get a $30\%$ discount off of the original price. She is then charged a $7\%$ tax on the discounted price.What is the final cost for Luisa's plane ticket? NO LINKS..... There are 39 people on a city bus. The ratio of adults to children is 10:3. At the next stop, 3 adults get off the bus. What is the new ratio of adults to children on the bus? A. 3:1 B. 9:2 C. 7:3 D. 12:1 PLEASEEE ANSWER PLEASEEE PLEASE Ill mark brainliest Can anyone help me with this please I really need help with this rq . which virtues help us to realize peace Class 8 moral education which goal motivated the civil rights movement? Choose exactly two answers that are correct.Ending segregation by eliminating "Jim Crow" laws.Abolishing slavery and all forms of forced labor.Keeping whit students from attending black schools.Protecting the equality and full citizenship of African Americans. Brian makes a valiant effort to use as much of each animal as he can. Aside from using the moose as a source of food, what else has he made out of the moose? A. A scarf B. A pair of socks C. A comforter D. A coat what was the purpose of the virginia house of burgesses Will give 20 points I need help with the question below Copper 11 oxide and charcoal are black solids . How would you distinguish between the two solids Please help 20 points Why is it difficult to define the boundaries of a functional region? (5 points)A. Geographers cannot measure the culture of people in a functional region.B. Functional regions depend on peoples mental images of places.C. Many different characteristics define functional regions.D. Functional regions radiate out from a defined center.E. Different populations will have different viewpoints on the boundaries of the region. Identify the kind of sample that is describedThe student government association at a certain college chooses three classes, at random, being taught during a given semesterand samples all students in those classes to ask about a new grading policy. The position-time graph for two drivers (A and B) are shown in the figure below. Which of the following statements is correct?a. The two drivers are for sure moving in parallel directionsb. Driver B is moving faster than driver A.c. Driver A is moving faster than driver B.d. The two drivers are moving at the same speed Investing $10,000 in a savings account at 3% annual interest compounded monthly will result in approximately how much money after10 years?formula: A = P(1 + r/m)^mtO $10, 564.68O $13, 439.16O $13, 493.54O $13,000.00 Solve for x.2x-30/X+6090507020 A _________ is an organic compound that must be obtained from the diet and is needed to sustain life. PLEASE HELP WITH THIS ONE QUESTION What is the z-score of x, when x = 1 and X ~ N (12,3)? Must Show Working