Question

Write a Python program that does the following: Obtains the following input from a user: Mileage...

Write a Python program that does the following:

Obtains the following input from a user:

Mileage at beginning of measurement period

Mileage at end of measurement period

Gallons of fuel consumed

Calculates and displays:

Miles driven

Miles per gallon

Kilometers driven

Liters of fuel consumed

Kilometers per liter

Incorporate some Selection structure logic into it:

If a vehicle gets less than 15 miles per gallon, display the message:

      "Your vehicle has criminally low fuel efficiency."

If it gets 15 or more but less than 20, display:

      "Your vehicle has undesirably low fuel efficiency."

If it gets 20 or more but less than 25, display:

      "Your vehicle gets barely acceptable efficiency."

If it gets 25 or more but less than 35, display:

      "Your vehicle gets high fuel efficiency."

If it gets 35 or more, display:

      "Your vehicle gets outstanding fuel efficiency."

Incorporate Hardcoded Data stored in Lists:

The program needs 3 lists representing the items of input – mileage at beginning of the measurement period, mileage at end of the period and gallons of fuel consumed – we'll create three lists – one for beginning mileage, a second for ending mileage and a third for gallons consumed – and hardcode the data in them. By iterating through a loop which has statements for retrieving elements from these lists, the program will obtain the input it needs for performing calculations and producing output. Create the lists and load data into them before the loop.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Create the lists and load data into them before the loop.

Below is the python code:

#Create the lists and load data into them before the loop.
MilageAtBegining=[0]*10
MilageAtTheEnd=[0]*10
Gallons=[0]*10
MilageAtBegining[0]=int(input("Enter the milage measurement at the 1st trip Begining "))
MilageAtTheEnd[0]=int(input("Enter the milage measurement at the 1st trip End "))
Gallons[0]=int(input("Enter The Gallons Consumed in the 1st trip travel"))
MilageAtBegining[1]=int(input("Enter the milage measurement at in 2nd trip of the Begining "))
MilageAtTheEnd[1]=int(input("Enter the milage measurement at in 2nd trip of the End "))
Gallons[1]=int(input("Enter The Gallons Consumed in 2nd trip of the travel"))
MilesDriven=0
G=0
#infact you can take the inputs in the loop also and get the number of trips as i
for i in range(3):#i indicates the number of trips
  
        MAB=MilageAtBegining[i]
        MAE=MilageAtTheEnd[i]  
        MilesDriven+= MAE-MAB
        G+=Gallons[i]
        print("Miles Driven for ",i+1," Trip ",MAE-MAB," miles Gallons Consume ",Gallons[i])
      
MilesPerGallon=MilesDriven/G
LitersofFuel=G*3.78#coversion of gallons to liters
Km=MilesDriven*1.60#miles to km
KmL=Km/LitersofFuel
if(MilesPerGallon<=15):
    print("Your Vehicle has criminally low fuel efficency")
elif(MilesPerGallon>15 and MilesPerGallon<=20):
    print("YOur vehicle has undesrably low fuel efficency")
elif(MilesPerGallon>20 and MilesPerGallon<=25):
    print("YOur vehicle gets barely acceptable efficiency. ")
elif(MilesPerGallon>25 and MilesPerGallon<=35):
    print("Your vehicle gets high fuel efficiency")
else:
    print("Your vehicle gets outstanding fuel efficiency.")

Output:-

Add a comment
Know the answer?
Add Answer to:
Write a Python program that does the following: Obtains the following input from a user: Mileage...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program that does the following: Obtains the following input from a user: Mileage...

    Write a Python program that does the following: Obtains the following input from a user: Mileage at beginning of measurement period Mileage at end of measurement period Gallons of fuel consumed Calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Also incorporate some selection structure logic into it. If a vehicle gets less than 15 miles per gallon, display the message:       "Your vehicle has criminally low fuel efficiency." If it gets...

  • You previously wrote a program that calculates and displays: Miles driven Miles per gallon Kilometers driven...

    You previously wrote a program that calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Messages commenting on a vehicle's fuel efficiency And also validates input Now we'll make a somewhat major change. We'll remove the code for obtaining input from a user and replace it with hardcoded data stored in lists. Because the data is hardcoded, the program will no longer need the code for validating input. So, you may remove...

  • The Python program will compute total mileage for all trips included : Trip: 1,2,3,4 Mileage: 200,...

    The Python program will compute total mileage for all trips included : Trip: 1,2,3,4 Mileage: 200, 400, 800, 10 Gas: 10, 17, 39, 1 As well as the fuel efficiency in miles per gallon. Your program will open the file, read it line by line and add the miles driven and the gallons gas consumed then calculate the average fuel efficiency. It will then write Once the program has read all the lines, it will write the total miles driven,...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of gasoline by recording miles driven and gallons used for each tank. Develop a program using a while loop that will input the miles driven and the gallons used for each tank. The program should calculate and display the miles per gallon obtained for each tank. After processing all input information, the program should calculate and print the overall miles per gallon...

  • In Visual Basics - Program 2. Mileage Write a program which allows the user to enter...

    In Visual Basics - Program 2. Mileage Write a program which allows the user to enter the distance they have traveled by car in miles and the number of gallons of gasoline they used to travel the distance. Be sure to allow for decimal places for both values. Your results should show miles per gallon and kilometers per gallon. A kilometer is 0.61 miles, and this value must be stored as a constant. Your outputs must be formatted to 2...

  • C++, Visual Studio 3. Define a class called Odometer that will be used to track fuel...

    C++, Visual Studio 3. Define a class called Odometer that will be used to track fuel and mileage for an automobile. The class should have instance variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer's total, and...

  • Write program PSEUDOCODE that prompts the user for their name and then will compute a car's...

    Write program PSEUDOCODE that prompts the user for their name and then will compute a car's miles per gallon given input of miles driven and gallons of gas used. It should also convert those given numbers into metric and show kilometers driven, liters used, and kilometers per liter. All with well formatted output. Submit: C++ Programming Warm-Up Exercise PSEUDOCODE for the algorithm that compute's a car's miles per gallon given input of miles and convert these numbers into metric and...

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls....

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT