Code for calculating Miles Per Gallon with Python Program
# taking input from user for miles miles = input("Enter miles driven: ") # converting to float miles = float(miles) # taking input from user for gallon gallon = input("Enter gallon used: ") # converting to float gallon = float(gallon) # calculating miles per gallon in python miles_per_gallon = miles / gallon # printing miles_per_gallon print("Miles per gallon: ", miles_per_gallon)
Output:
So, this is a simple Miles Per Gallon Python Program to calculate how many miles you drive in 1 gallon of oil.
What is a gallon?
A gallon is a unit of volume in imperial units and the United States customary units. Three different versions are in current use. Click here to know more about a gallon.
We hope this article will help you.
Thank you for visiting our website.
Also Read:
- What is web development for beginners?
- Python | Check Armstrong Number using for loop
- Python | Factorial of a number using for loop
- What does if __name__ == __main__ do in Python?
- Python | CRUD operations in MongoDB
- Create your own ChatGPT with Python
- Radha Krishna using Python Turtle
- Python Programming Examples | Fundamental Programs in Python
- Python | Delete object of a class
- Python | Modify properties of objects
- Python classmethod
- Python | Create a class that takes 2 parameters, print both parameters
- Python | Create a class, create an object of the class, access, and print property value
- Python | Find the maximum element in a list using lambda and reduce()
- Python | filter numbers(that are not divisible by 3 and 4) from a list using lambda and filter()
- Python | lambda function that returns the maximum of 2 numbers
- Python | Convert all strings of a list to uppercase using lambda
- Python | Square numbers of a list using lambda
- Python | Reverse and convert a string to uppercase using lambda
- Python | Convert String to uppercase using lambda
- Python | Reverse a list using lambda
- Python | Calculator using lambda
- Python | Square of a number using lambda
- Python | Multiply numbers using lambda
- Python | lambda with None
- Python | lambda with pass statement
- Python | Add numbers using lambda
- Python | Print Namaste using lambda
- Iterate over a string in Python
- Python | join() | Join list of strings