1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vovangra [49]
4 years ago
12

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

s 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. Note: This is a lab from a previous chapter that now requires the use of a function.
Computers and Technology
2 answers:
Aneli [31]4 years ago
6 0

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

  gallon_used = driven_miles / miles_per_gallon

  cost = gallon_used * dollars_per_gallon  

  return cost  

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Explanation:

Alexus [3.1K]4 years ago
3 0

Answer:

  1. def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
  2.    gallon_used = driven_miles / miles_per_gallon
  3.    cost = gallon_used * dollars_per_gallon  
  4.    return cost  
  5. miles_per_gallon = float(input("Input miles per gallon: "))
  6. dollars_per_gallon = float(input("Input dollar per gallon: "))
  7. cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)
  8. cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)
  9. cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)
  10. print("$ %.2f" % cost1)
  11. print("$ %.2f" % cost2)
  12. print("$ %.2f" % cost3)

Explanation:

The solution is written in Python 3.

Firstly, create a function driving_cost that takes three parameters, driven_miles, miles_per_gallon and dollars_per_gallon (Line 1). In the function, calculate the gallon consumption by applying formula driven_miles / miles_per_gallon and then use it to calculate the cost (Line 2 - 3). Return the cost as output (Line 4).

In the main program, prompt user to input miles per gallon and dollars per gallon and then use these input values as arguments to call the function driving_cost function for three times with each time with different driven_miles value (Line 6 - 11).

At last, use formatted print to display the output to two decimal points (Line 13 - 15).

You might be interested in
Which of these is a benefit of using the Sort option?​
Reika [66]

There are many benefits of using the shot options in Excel. Some benefits are allowing you to short by number,date,color, letter, columns,or text. This benefits the user because it allows the user to bring data up more easily.

I hope this answers is helpful

3 0
3 years ago
A web-based application encounters all of the connectivity and compatibility problems that typically arise when different hardwa
andrezito [222]

Answer:

False

Explanation:

A web-based application encounters connectivity and compatibility relate to data server. It does not belong to any hardware environments.

A web based application is accessed over network.They run inside a web browser. Small of program is download to user's desktop, but this processing is done over internet.

6 0
3 years ago
During the forensic phase of a security investigation, it was discovered that an attacker was able to find private keys on a poo
Paraphin [41]

Answer:

C. Man-in-the-middle; well-controlled storage of private keys.

Explanation:

During the forensic phase of a security investigation, it was discovered that an attacker was able to find private keys on a poorly secured team shared drive, thus describing a well-controlled storage of private keys.

The attacker using those keys to intercept and decrypt sensitive traffic on a web server is a Man-in-the-middle attack.

5 0
4 years ago
Using the same formatting elements and designs across slides in a presentation is important to develop what vital quality?
Monica [59]

a

please give branliest

6 0
3 years ago
Read 2 more answers
You play guitar and keep two files on your computer. One file, called strings, lists the different brands of strings you keep on
Hoochie [10]

Answer is given below

Explanation:

  • when performing in computer and we have two files on the computer first one is string and another one is the music list                
  • so when we enter the command paste strings music than there will they display side by side on the screen.
  • and on the left side of lists the string in screen and the right side is columns list the music book              
7 0
3 years ago
Other questions:
  • Is anyone familiar in drawing flow charts for c++ programming
    14·1 answer
  • Under the class system, how many host ids were available in a class b network?
    7·1 answer
  • Technological improvements have allowed people to inhabit a wider variety of places more easily. Please select the best answer f
    6·2 answers
  • Which variable name is the best to hold the area of a rectangle?<br> 1A<br> area<br> AREA<br> a
    13·1 answer
  • ​the complete definition of a database, including descriptions of all fields, tables, and relationships, is called a _____.
    7·1 answer
  • Discuss trends in cellular data transmission speeds
    15·2 answers
  • A macro enables you to automate repetitive tasks by
    5·1 answer
  • What is an Action Button?
    10·1 answer
  • Which of the following can computer maintenance software determine?
    6·1 answer
  • what should the timing of transition slides be per minute? maintain the flow of the presentation to ______ slides per minute.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!