Question

Task: Write functions for each container type. Prompt the end-user to enter the volume of water...

Task:

Write functions for each container type.

Prompt the end-user to enter the volume of water for the pool, then produce a report with the number needed of each container.

Given a swimming pool with a specific volume of water tell me how many of each do I need to empty the pool, and if anything remains, how much? Each container has to be filled to it's maximum capacity. For example a 74 gallon pool will fill 2 garbage cans and 1 bucket, with nothing remaining.

Volumes

Garbage can = 32 gallons

Bucket = 5 gallons

Pail = 1 gallon

Quart = .25 gallons

Pint = .125 gallons

Cup = .0625 gallons

Be able to write this in python

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

Python code:

# Defining findVolume function
def findVolume(volume):
# if volume is greater than or equal to 32 gallons.
if(volume >=32):
n = volume//32
print(int(n),'Garbage can') # display Garbage cans.
st = n*32
volume = volume-st # Remaining volume.
  
# if volume is greater than or equal to 5 gallons.
if(volume >=5):
n = volume//5
print(int(n),'Bucket')
st = n*5
volume = volume -st # Remaining volume.
  
# if volume is greater than or equal to 1 gallons.
if(volume >=1):
n = volume//1
print(int(n),'Pail')
st = n*1
volume = volume-st # Remaining volume.

# if volume is greater than or equal to 0.25 gallons.
if(volume >=0.25):
n = volume//0.25
print(int(n),'Quart')
st = n*0.25
volume = volume-st

# if volume is greater than or equal to 0.125 gallons.
if(volume >=0.125):
n = volume//0.125
print(int(n),'Pint')
st = n*0.125
volume = volume-st # Remaining volume.
  
# if volume is greater than or equal to 0.0625 gallons.
if(volume >=0.0625):
n = volume//0.0625
print(int(n),'Cup')
s = n*0.0625
volume = volume - st # Remaining volume.
  
# display the Remaining volume
print('Remaining volume:',round(volume,3))
  

# __name__
if __name__=="__main__":
  
# Taking the user input and storing it in variables name volume.
volume=float(input('Enter the volume of water for the pool: '))
# display the message
print(volume,'gallon pool will fill: ')
# Calling the findVolume method with 1 parameter.
findVolume(volume)

Python code screenshot:

# Defining findVolume function def findVolume (volume): # if volume is greater than or equal to 32 gallons. if(volume >=32):# if volume is greater than or equal to 0.125 gallons. if(volume >=0.125): n = volume//0.125 print(int(n), Pint) st = n*0.1

OUTPUT:

Enter the volume of water for the pool: 55 55.0 gallon pool will fill: 1 Garbage can 4 Bucket 3 Pail Remaining volume: 0.0

Add a comment
Know the answer?
Add Answer to:
Task: Write functions for each container type. Prompt the end-user to enter the volume of water...
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
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