I do not understand python very well. I need this prograam in python. I am strug
ID: 3662997 • Letter: I
Question
I do not understand python very well. I need this prograam in python. I am struggling doing this homework. Please someone show me how to do in python this problem. Do not skip step. Please.
1. fluidConversion
Function Name: fluidConversion Parameters:
None
Return Value:
None
Description:
Write a user-interactive function to convert any number of fluid ounces to the equivalent number of gallons, quarts, pints, and gills.
1. Get the number of fluid ounces as an integer from the user; make sure to use a descriptive prompt so the user knows what to enter.
Calculate the total number of gallons, quarts, pints, and gills represented by the original number of fluid ounces, using the following hints:
-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.
-The modulo (a.k.a. remainder) operator in python is % and will show the remainder left after an integer division. It IS useful for this problem!
Print the calculated number of gallons, quarts, pints, and gills on one line; be sure to add appropriate labels to the display values so the user knows what the value means (e.g. if the user enters 6523 fluid ounces, you should display “6523 fluid ounces is 50 gallon(s), 3 quart(s), 1 pint(s), and 2 gill(s))
Explanation / Answer
def fluidConversion():
fl=input("Enter the fluid value : ")
fluid=int(fl)
fluid2=fluid
gallons=fluid/128
fluid=fluid%128
quarts=fluid/32
fluid=fluid%32
pints=fluid/16
fluid=fluid%16
gills=fluid/4
gills=fluid%4
print(fluid2," fluid ounces is ",gallons," gallon(s) ", quarts," quart(s) ",pints," pint(s) and ",gills," gill(s)")
return;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.