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
butalik [34]
3 years ago
8

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, 5

0 miles, and 400 miles. Ex: If the input is 20.0 3.1599, the output is: 1.57995 7.89975 63.198 Note: Small expression differences can yield small floating-point output differences due to computer rounding. Ex: (a + b)/3.0 is the same as a/3.0 + b/3.0 but output may differ slightly. Because our system tests programs by comparing output, please obey the following when writing your expression for this problem. First use the dollars/gallon and miles/gallon values to calculate the dollars/mile. Then use the dollars/mile value to determine the cost per 10, 50, and 400 miles. Note: Real per-mile cost would also include maintenance and depreciation.
Computers and Technology
1 answer:
omeli [17]3 years ago
5 0

Answer:

The Following are the code to this question:

def cost(miles, milesPerGallon, dollarsPerGallon):##defining a method cost that accepts three parameter

   return miles / milesPerGallon * dollarsPerGallon# calculate cost and return it value  

milesPerGallon = float(input('Enter miles/Gallon value: '))#defining variable milesPerGallon for user input  

dollarsPerGallon = float(input('Enter dollars/ Gallon value: '))#defining variable dollarsPerGallon for user input

print('{:.5f}'.format(cost(10, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.5f}'.format(cost(50, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.3f}'.format(cost(400, milesPerGallon, dollarsPerGallon)))#call method and print its value

Output:

Enter miles/Gallon value: 20.0

Enter dollars/ Gallon value: 3.1599

1.57995

7.89975

63.198

Explanation:

In the above-given code, a method "cost" is defined, that accepts three value "miles, milesPerGallon, and dollarsPerGallon" in its parameter, and use the return keyword for calculating and return its value.

In the next step, two variable "milesPerGallon, and dollarsPerGallon" is declared, that use the input method with float keyword for input floating-point value.

After input value, it uses a print method with different miles values, which are "10,50, and 400", and input value to pass in cost method to call and print its return value.

You might be interested in
Whose massively popular photo led to the creation of google images?
Alex
Jennifer Lopez’s picture led to the creation of google images.
5 0
3 years ago
Which type of password provides the highest level of permissions in bios?
OLEGan [10]
<span>Which type of password provides the highest level of permissions in bios? = Supervisor provides the highest level of permissions in the BIOS</span>
6 0
3 years ago
Please help me idk I suck at this stuff ​
kap26 [50]
I would say the best clear answer is D, because A is a little bit unclear but I would say the best answer is D.

Why?

Mesh Topology is expensive considering more links as compared to Ring topology.


4 0
2 years ago
Which of the following statements is false?
GrogVix [38]

Answer:

bnnnnn A1

Explanation:

bnnnnnjm

8 0
2 years ago
A laptop computer is smaller than desktop computer. True or false
alina1380 [7]

Answer:

true

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • What task can a user accomplish by customizing theme colors?
    14·2 answers
  • Weber believed that there is an inevitable destructive quality to which one of the four types of action?
    8·1 answer
  • What is the solubility of an empty soda can
    10·1 answer
  • Read each statement below. If the statement describes a peer-to-peer network, put a P next to it. If the statement describes a s
    12·1 answer
  • Coment on this if your user starts with dida
    5·1 answer
  • How to write cube of a number from flowchart ​
    5·1 answer
  • The first page of a website is what?​
    5·2 answers
  • Privacy, anonymity, and freedom of expression are all interrelated.
    12·1 answer
  • Only cool people answer this question.<br><br><br><br><br> are you cool?
    11·2 answers
  • What component of a game makes victories feel earned and helps the player become physchologically engaged by the play experience
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!