answer.
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]
2 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]2 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]2 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
What is retrieved from a search containing two terms separated<br> by the AND operator?
egoroff_w [7]

Answer:

A AND B= 1 or 0

1 1  1

0 1  0

1 0  0

0 0 0

So, as explained above if both are 1 we then only get 1, or else we get 0 always in case of AND which is a logical operator, whose output can be 0 or 1 only. This is being depicted above.

Explanation:

If both are 1 we get 1 or always else, we get the output =0.

8 0
1 year ago
A data center designer requested additional lighting for the entrance to the data center as well as the removal of a object whic
Ira Lisetskai [31]

Answer:

SURVEILLANCE-SPECIFIC DESIGN.

Explanation:

Defensible space offers a series of architectural guidelines that can be used in the design of new urban residential complexes to promote both the residential group’s territorial claim to its surroundings and its ability to conduct natural surveillance. The designs are: site interrelationship design, site design, street design and surveillance-specific design.

Surveillance-specific design can be used to increase general visibility by providing adequate lighting, by reducing or eliminating physical barriers to visibility, and by the visibility-promoting location of key areas (entrances, lobbies, elevator waiting areas, parking areas e.t.c.) so as to be directly visible from as many viewpoints as possible.

Since the data center designer requested additional lighting for the entrance to the data center as well as the removal of a object which is blocking security's view of the entrance, then it is an example of SURVEILLANCE-SPECIFIC DESIGN.

6 0
1 year ago
1. What should you do if your computer is shared by your entire family and you install a plugin that saves user names and passwo
Citrus2011 [14]

Explanation:

1 make sure only you know the password

2 having weak security on one browser is basically a doorway for someone to get into your network

7 0
1 year ago
Read 2 more answers
The it department is reporting that a company web server is receiving an abnormally high number of web page requests from differ
Talja [164]
<span>In the scenario in which the IT department is reporting that a company web server is receiving an abnormally high number of web page requests from different locations simultaneously the DDoS security attack is occurring.
</span>DDos stands for Distributed Denial of Service<span> . This </span><span>attack is an attempt to make an online service unavailable by overwhelming it with traffic from multiple sources.</span>
8 0
1 year ago
The act of engaging in crime through the use of a computer or similar type of device is called:
marin [14]
I don’t have an explanation for why it is called this, because really the name of it is in its definition. The two words this sentence describes are cybercrime and computer crime. They are both the same thing.
8 0
1 year ago
Other questions:
  • Which item is essential to know before sketching a navigation menu flowchart? template specifics, such as horizontal or vertical
    12·1 answer
  • All the employees of Delta Corporation are unable to access the files stored in the server. What do you think is the reason behi
    14·1 answer
  • Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then th
    12·1 answer
  • Escribe, en los siguientes cuadros, los conceptos que correspondan
    10·1 answer
  • Match common encryption algorithms and methods with the scenarios representing real-world business applications and requirements
    14·1 answer
  • In defining security implemention, what are the roles of the following committees. 1) gateway committee 2) project committee 3)
    8·1 answer
  • Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation
    6·1 answer
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    10·1 answer
  • Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working. Describe each pos
    14·1 answer
  • The Company management has asked that you compare the OSSTMM and the PTES to determine which methodology to select for internal
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!