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
Troyanec [42]
3 years ago
9

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 20 miles, 75 miles, and 500 miles.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3))

Ex: If the input is:

20.0
3.1599
Then the output is:

3.16 11.85 79.00
Computers and Technology
2 answers:
Katen [24]3 years ago
8 0

Answer:

# Program in Python

# Take miles/gallon as input from user

miles_per_gallon = float(input('Please enter cars miles/gallon: '))

# Take dollars/gallon as input from user

dollars_per_gallon = float(input('Please enter gas dollars/gallon: '))

# Formula for calculating gas cost

dollars_per_mile = dollars_per_gallon/miles_per_gallon

# Gas cost for 20 miles

your_value1 = 20 * dollars_per_mile

# Gas cost for 75 miles

your_value2 = 75 * dollars_per_mile

# Gas cost for 500 miles

your_value3 = 500 * dollars_per_mile

# Display the results as output

print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3))

Explanation:

First of all take miles/gallon and dollars/gallon as input from user  and store them in their respective variables. Then calculate the gas cost by dividing dollars/gallon with miles/gallon. Multiply this calculated cost with 20, 75 and 500 respectively. Finally display the results by using print statement.

Output:

Please enter cars miles/gallon: 20.0

Please enter gas dollars/gallon: 3.1599

3.16 11.85 79.00

hram777 [196]3 years ago
8 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:

You might be interested in
Which of the following is not true about designing classes? In order for class information to be printed instead of a memory add
Leokris [45]
'<span>All methods should be declared private</span>' is not true for classes. One should be able to change the properties of objects, and to do this safely and in a controlled manner, some public methods are declared. Some private methods can also be declared for more potentially sensitive operations for being called from within the class. 
6 0
4 years ago
A variable used as a subscript should be initialized to ________.
jeyben [28]
The answer is d. Two
Two variables referring to the same array object
6 0
3 years ago
1. [10 marks] We begin with some mathematics regarding uncountability. Let N = {0, 1, 2, 3, . . .} denote the set of natural num
crimeas [40]

Answer:

Please see attachment

Explanation:

Please see attachment

Download pdf
6 0
4 years ago
Iven an array temps of double s, containing temperature data, compute the average temperature. Store the average in a variable c
ale4655 [162]

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class num1 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter length of the array:");

       int len = in.nextInt();

       double [] temps = new double[len];

       double avgTem;

       int k =0;

       double total = 0;

       for( k=0; k<temps.length; k++){

           System.out.println("Enter values for the array");

           temps[k]=in.nextDouble();

       }

       System.out.println("The Arrays contains the following values");

       System.out.println(Arrays.toString(temps));

       // Computing the average of the values

       for(k=0; k<temps.length; k++){

           total = total+temps[k];

       }

       avgTem = total/(temps.length);

       System.out.println("The average Temperature is: "+avgTem);

   }

}

Explanation:

  • Using Java programming language
  • Import the Scanner class to receive user input
  • Prompt User for the length of the Array, receive and store in a variable len;
  • Declare a new double array of size len double [] temps = new double[len];
  • Using a for loop, continually prompt user to enter values into the array
  • Display the values of the array using Java's Arrays.toString method
  • Use another for loop to add up all the elements in the arraay and store in the variable called total
  • Outside the second for loop calculate the average avgTem = total/(temps.length);
  • Display the average temp.
6 0
3 years ago
This algorithm requires you to find the perimeter of 12 different squares.
k0ka [10]

Answer:

BEGIN

SET count = 1

WHILE count <= 12 THEN

     INPUT length

     perimeter = length * length

     PRINT perimeter

END WHILE

END

Explanation:

You can also set count to 0 and in while loop use count < 12 to loop just 12 times just as above

4 0
3 years ago
Other questions:
  • You can choose to use a window manager only, and not use a desktop manager.
    8·2 answers
  • In the INSERT statement that follows, assume that all of the table and column names are spelled correctly, that none of the colu
    9·1 answer
  • Which tab is used to edit objects on the slide master and layouts
    10·1 answer
  • While editing a film, a director feels that the actors have not enacted a particular scene well. What type of shot must the dire
    12·1 answer
  • Which statement about comments is false? Select one: a. Lengthy comments can cause poor execution-time performance. b. Comments
    7·1 answer
  • The Gauss-Seidel method as an iterative technique often refers to an improved version of the Jacobi method, since the Gauss-Seid
    13·1 answer
  • Rachel needs to include a new organizational chart in her project. Which type of illustration should she use?: *
    11·1 answer
  • How do you suppose a request travels from one computer to another? How does the request know where to go?
    8·1 answer
  • Haya would like to complemely delete Slide 11 from her presentation so that slides 12–16 become slides 11-15. What is
    9·1 answer
  • Which of the following is a software tool used to manage data for a project in a logical and hierarchical order?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!