Question

In: Computer Science

Write a program that will calculate and display the cost of a gasoline purchase based on...

Write a program that will calculate and display the cost of a gasoline purchase based on the brand of gasoline, the octane rating and the amount purchased.

Your program should first display a menu prompting the user for the brand of gasoline.  Next prompt the user for the amount of gasoline in liters.

Finally, your program should calculate and display the cost of the gasoline purchase using the formula below.

  • Cost of Discount Gasoline = ($2.49 - (100 - Octane Rating) * 0.01) * Number of Gallons
  • Cost of Premium Gasoline = ($2.99 - (100 - Octane Rating) * 0.01) * Number of Gallons

Notice that the units of measure for the amount of gasoline in the formula are in gallons (not liters).  You will need to convert liters into gallons using this conversion factor: 1 liter = 0.264172 gallons

Sample Input and Output (output should match exactly, including decimal scale)

CPCC Gasoline Services

  1. Discount
  2. Premium

Enter the brand type: 2

Enter the octane rating: 90

Enter the amount of gasoline in liters: 68.04

The cost of the gasoline is $51.95

Solutions

Expert Solution

#printing initials
print('CPCCC Gasoline Services')
print('Discount')
print('Premium')

#taking inputs
brand=int(input("Enter the brand type: "))
rating=int(input("Enter the octane rating: "))
liters=float(input("Enter the amount of gasoline in liters: "))

#changing liters to gallons
gallons=float(liters*0.264172)

#calculating cost according to type of brand
if brand==1:
    cost=float((2.49-(100-rating)*0.01)*gallons)
elif brand==2:
    cost=float((2.99-(100-rating)*0.01)*gallons)
    
#rounding cost to 2 decimal places
cost=round(cost,2)

#printing cost
print("The cost of the gaasoline is $",cost)

OUTPUT:


Related Solutions

Write a program to calculate the area and circumference of a cuboid. Use printf to display...
Write a program to calculate the area and circumference of a cuboid. Use printf to display 2 digits after decimal point in all the results Program should be in java language.
Question 1: Write an AVR program to display text on a 2-line WH2002 LCD display based...
Question 1: Write an AVR program to display text on a 2-line WH2002 LCD display based on the HD44780 controller. Apply the following: The LCD instruction/data bus is connected to PORTD, and control bus is connected to PORTB (RS is connected to PB0, R/W to PB1, E to PB2). Use the #define command to name PORTD as Display_port. Use the #define command to name PORTB as Control_port. The displayed information is stored in the microcontroller Flash ROM (maximum size of...
Write a program to use Math methods to calculate and display the followings: Prompts the user...
Write a program to use Math methods to calculate and display the followings: Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is...
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
Write a C++ program to display toy name
Write a C++ program to display toy name
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants to create an insurance management system for their clients. The insurance management system will compute the required payments from the clients. The commission of the agent shall also be computed which depends on the amount of insurance type. Insurance Type Amount of Insurance type Agent Commission Life 2500 12.5% of amount Health 1500 10.5% of amount Other inputs 0 0 Computation of monthly payments...
Write a PHP Program to display all the $_SERVER elements
Write a PHP Program to display all the $_SERVER elements
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the...
Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the unit price and quantity of a product input by the user. (use if and if-else statements) • The discount rate is o 0% for the quantity purchased between 1 and 49 units. o 10% for the quantity purchased between 50 and 99 units. o 15% for the quantity purchased between 100 and 149 units. o 25% for the quantity purchased greater than or equal150...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT