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 program that will calculate the cost of installing fiber optic cable at a cost...
Write a program that will calculate the cost of installing fiber optic cable at a cost of .87 per ft for a company. Your program should display the company name and the total cost. Display a welcome message for your program. Get the company name from the user Get the number of feet of fiber optic to be installed from the user Multiply the total cost as the number of feet times .87. Display the calculated information and company name.
Write a C++ program to display toy name
Write a C++ program to display toy name
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display...
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display the student's name, and a letter grade such as A, B, C, D, or F. It shall have a Student class with necessary private data members and constructor and public methods, such as getName, getGrade, calcScore, convertToGrade, etc. Try to create a Student object in main(), then invoke its methods to perform the tasks.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT