16 Dec Aurora Saturday 13:00 Python Practice 12.12.
Question:
Create an FluidConversion object to convert any number of fluid units to the equivalent number of gallons, quarts, pints, and gills. (There are 128 fluid ounces in a gallon. There are 32 fluid ounces in a quart. There are 16 fluid ounces in a pint. There are 4 fluid ounces in a gill.)
- Get the number of fluid gallons, quarts, pints, gills and ounces as integer from the user; make sure to use a descriptive prompt so the user knows what to enter, for example:
Sample input: Please enter fluid gallons: Please enter fluid quarts: Please enter fluid pints: Please enter fluid gills: Please enter fluid ounces:
- The object contains methods to calculate the total number of gallons, quarts, pints, and gills represented by the original number of fluid ounces and print it out. for example:
- convertGallons() – it just simply convert into gallons, the method will have a return value
- convertQuarts() – it just simply convert into quarts, the method will have a return value
- convertPints() – it just simply convert into pints, the method will have a return value
- convertGills() – it just simply convert into gills, the method will have a return value
- convertOunces() – it just simply convert into the ounces, the method will have a return value
- convert() – convert any number of fluid units to the equivalent number of gallons, quarts, pints, and gills. for example:
- “1 Gallon 6523 fluid ounces is 51 gallon(s)+3 quart(s)+1 pint(s)+2 gill(s)+3 ounce(s)”
- Define __str__(self) show calculated number of gallons, quarts, pints, gills and ounce in one line, for example:
- “6523 fluid ounces is 50 gallon(s)+3 quart(s)+1 pint(s)+2 gill(s)+3 ounce(s)”
Sample program as below:
class FluidConversion: def __init__(self, gallons=0, quarts=0, pints=0, gills=0, ounces=0): ... def convertGallons(self): ... def convertQuarts(self): ... def convertPints(self): ... def convertGills(self): ... def convertOunces(self): ... def convert(self): ... def __str__(self): ... gallons = int(input('Gallons: ')) quarts = int(input('Quarts: ')) pints = int(input('Pints: ')) gills = int(input('Gills: ')) ounces = int(input('Ounces: ')) fc = FluidConversion(gallons, quarts, pints, gills, ounces) print('it is', fc.convertGallons(), 'gallons') print('it is', fc.convertQuarts(), 'quarts') print('it is', fc.convertPints(), 'pints') print('it is', fc.convertGills(), 'gills') print('it is', fc.convertOunces(), 'ounces') print(fc) fc.convert() print(fc)
Sorry, the comment form is closed at this time.