Question

In: Computer Science

Write a beginner's program in Python to determine your car's gas mileage. You should use the...

Write a beginner's program in Python to determine your car's gas mileage. You should use the input variables "miles_traveled" and "gallons_fuel" and the result should be stored in the variable "miles_per_gallon".

Solutions

Expert Solution

Solution for the given question are as follows -

Code :

# get inputs from user
print('Enter Total Miles Traveled : ')
total_miles_traveled = int(input())
print('Enter Current Miles Traveled : ')
miles_traveled = int(input())
print('Enter Gallons Fuel : ')
gallons_fuel = int(input())

# calculate miles_per_gallon
miles_per_gallon = (total_miles_traveled - miles_traveled) / gallons_fuel

# print the result
print("Miles per Gallons : ", miles_per_gallon)

Code Screen Shot :

Output :


Related Solutions

City Mileage, Highway Mileage. We expect a car's highway gas mileage to be related to its...
City Mileage, Highway Mileage. We expect a car's highway gas mileage to be related to its city gas mileage (in miles per gallon, mpg). Data for all 1137 vehicles in the government's 2013 Fuel Economy Guide give the regression line highway mpg = 6.785 + (1.033 x city mpg) for predicting highway mileage from city mileage. (a) What is the slope of this line? Say in words what the numerical value of the slope tells you. (b) What is the...
In Europe, gasoline efficiency is measured in km/L. If your car's gas mileage is 22.0 mi/gal...
In Europe, gasoline efficiency is measured in km/L. If your car's gas mileage is 22.0 mi/gal , how many liters of gasoline would you need to buy to complete a 142-km trip in Europe? Use the following conversions: 1km=0.6214mi and 1gal=3.78L. While in Europe, if you drive 107 km per day, how much money would you spend on gas in one week if gas costs 1.10 euros per liter and your car's gas mileage is 28.0 mi/gal ? Assume that...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Driving costs - functions Driving is expensive. Write a program with a car's miles/gallon and gas...
Driving costs - functions Driving is expensive. 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, 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,...
1. Write Python program that use a while loop to determine how long it takes for...
1. Write Python program that use a while loop to determine how long it takes for an investment to double at a given interest rate. The input will be an annualized interest rate, and the output is the number of years it takes an investment to double. Note: The amount of initial investment can be any positive value, you can use $1. 2. Write a function def DoubleInvest(initialInvest) to perform the same functionalities as question1. Make sure to include you...
Write a Python program to determine the body-mass index of a collection of six individuals. Your...
Write a Python program to determine the body-mass index of a collection of six individuals. Your program should include a list of six names. Using a for loop, it should successfully prompt the user for the height in inches and weight in pounds of each individual. Each prompt should include the name of the individual whose height and weight are to be input. It should call a function that accepts the height and weight as parameters and returns the body...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works. 2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum 3. Program to compute the car insurance premium for a person based on their...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT