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
You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips
dmitriy555 [2]

Answer:

The c++ program for the scenario is given below.

#include <iostream>

using namespace std;

int main() {    

   int i,j, nZips, zipcodeList[nZips];

   bool duplicates;        

   cout<<"This program checks if duplicate values exist in the array." <<endl;    

   cout<<"Enter the number of integers to be inserted in the array."<<endl;

   cin>>nZips;    

   cout<<"Enter the integers to be inserted in the array."<<endl;    

   for(i=0; i<nZips; i++)

   {

       cin>>zipcodeList[i];

   }    

   for(i=0; i<nZips; i++)

   {

       for(j=0; j<nZips; j++)

       {

           if(i != j)

           {

               if(zipcodeList[i] == zipcodeList[j])

               {

                   duplicates = true;

                   cout<<"The value of duplicates variable is true meaning "<<duplicates<<endl;

                   break;

               }

               else

                   duplicates = false;

           }

       }

       

       if(duplicates == true)

               break;

}    

   if(duplicates == false)

       cout<<"The value of duplicates variable is false meaning "<<duplicates<<endl;    

   return 0;

}  

OUTPUT

This program checks if duplicate values exist in the array.

Enter the number of integers to be inserted in the array.

7

Enter the integers to be inserted in the array.

1234

2345

1234

5678

9087

6554

4560

3456

6789

The value of duplicates variable is true meaning 1  

Explanation:

The variables mentioned in the question are used as required. There is no logic applied to validate user input. It is assumed that user inputs only valid values.

This program is designed to check whether duplicate values are present in the array. The boolean variable duplicates is assigned value true or false depending on the presence of duplicate values.

The user is prompted the number of values to be put in the array along with those values.

Once the array is filled, the array is checked for identical values. If any identical value is present, the value of duplicates variable is assigned to true and the loop is discontinued.

If no identical values are present, the loop completes and duplicates variables is assigned the value of false.

In either case, the value of the duplicates variable is displayed.

3 0
2 years ago
Read 2 more answers
Jane's organization recently experienced a security incident that occurred when malware set to trigger on the chief executive of
inn [45]

Answer:

The answer is viruses

Explanation:

Because it is a harmful software hidden inside another  and usually performs a harmful action, such as destroying data.

4 0
2 years ago
Use the single-server drive-up bank teller operation referred to in Problems 1 and 2 to determine the following operating charac
elena-s [515]

Answer:

This question is incomplete, here's the complete question:

1. Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions without getting out of their cars. On weekday mornings, arrivals to the drive-up teller window occur at random, with an arrival rate of 24 customers per hour or 0.4 customers per minute. 3. Use the single-server drive-up bank teller operation referred to in Problems 1 to determine the following operating characteristics for the system: a.) The probability that no customers are in the system. b.) The average number of customers waiting. c.) The average number of customers in the system. d.) The average time a customer spends waiting. e.) The average time a customer spends in the system. f.) The probability that arriving customers will have to wait for service.

Explanation:

Arrival rate \lambda = 24 customers per hour or 0.4 customers per minute

Service rate \mu​ = 36 customers per hour or 0.6 customers per minute (from problem 1)

a.) The probability that no customers are in the system , P0 = 1 - \lambda / \mu

= 1 - (24/36) = 1/3 = 0.3333

b.) The average number of customers waiting

Lq = \lambda^2 / [\mu(\mu - \lambda)] = 242 / [36 * (36 - 24)] = 1.33

c.) The average number of customers in the system.

L = Lq + \lambda / \mu = 1.33 + (24/36) = 2

d.) The average time a customer spends waiting.

Wq = \lambda / [\mu(\mu - \lambda)] = 24 / [36 * (36 - 24)] = 0.0555 hr = 3.33 min

e.) The average time a customer spends in the system

W = Wq + 1/\mu = 0.0555 + (1/36) = 0.0833 hr = 5 min

f.) The probability that arriving customers will have to wait for service.

= 1 - P0 = 1 - 0.3333 = 0.6667

3 0
1 year ago
____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
Scrat [10]
<span>Spyware is a program placed on a computer without the user's knowledge that secretly collects information about the user.
</span><span>The spyware gathers information and can send this information to another program or entity which can take control over the device or use personal information to harm the user. </span>
7 0
2 years ago
Which of the following is an advantage of inserting a page number field in your document rather than inserting each page number
Artyom0805 [142]

The advantage of inserting the page number field is that the page number field could show the current page number.

The following information should be relevant with respect to the page number:

  • The page number field & the actual page number should be formatted.
  • The page number field & the actual page number both could be inserted into the header or footer.
  • The page number field & the actual page number could be easily inserted into the document.

Therefore we can conclude that the advantage of inserting the page number field is that the page number field could show the current page number.

Learn more about the page number here: brainly.com/question/3063419

8 0
1 year ago
Other questions:
  • What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
    13·2 answers
  • Edward has started up a new company with his friend, Matthew. Currently, he has only two people working with him. Which type of
    8·1 answer
  • Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user shoul
    13·1 answer
  • Given: an int variable k, an int array current Members that has been declared and initialized, an int variable memberID that has
    11·1 answer
  • Samuel received an email that looked like it came from his bank. The email told him to click a link that opened an official look
    7·1 answer
  • How can a signature be added to an email message? Check all that apply.
    10·2 answers
  • [Assembly Language]Extended Subtraction Procedure.Create a procedure named Extended_Sub --(Receives: ESI and EDI point to the tw
    12·1 answer
  • A company with a large number of hosts creates three subdomains under a main domain. For easier management of the host records,
    11·1 answer
  • What web 2.0 features allows users to subscribe to a data plan that charges for the amount of time spent on the internet?
    9·1 answer
  • The variable isopen is to be used to indicate whether or not a store is currently open. Which of the following is the most appro
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!