Write a beginner's Python program to determine how many gallons of water it would take to fill your pool, or your garage (if it were perfectly rectangular; ignore curves and cutouts), then calculate your water bill. In this challenge, you must choose your own input variables, variable names, and design your own tests to verify the program operation. The water used should be placed in an output variable called "gallons_used" and the cost should be placed in a variable called "water_cost"
When you click the Run Button, your program will be executed, and the value of the "gallons_used" and "water_cost" variables will be printed below.
Code:
length=int(input("Enter the Length of Pool in Feets : ")) #asking user to enter the length of pool in feets
breadth=int(input("Enter the Breadth of Pool in Feets : ")) #asking user to enter breadth of the pool in feets
depth=float(input("Enter the Depth of Pool in Feets : "))
#asking user to enter the depth of pool in feets
cost_of_gallon=3 #Assume cost of one gallon is 3 dollars
pool_volume=length*breadth*depth #finding volume of pool by multiplying length,breadth and depth
gallons_used=pool_volume*7.5 #7.5 is the multiplicating factor to calculate the no of gallons for rectangular and square type of pools
water_cost=gallons_used*cost_of_gallon #multiply cost_of_gallong with no_of_gallons
print("No of Gallons of water to fill the pool " + str(gallons_used)) #print the no of gallons of water required to fill the pool
print("Cost of water is $" + str(water_cost)) #print the cost of water
Code and Output Screenshots:
Note : Here the program has implemented in such a way that all values should be entered by user. The multiply factor 7.5 is used to calculate volume in gallons for square and rectangular type of pools.
Note : if you have any queries please post a comment thanks a lot..always available to help you..
Get Answers For Free
Most questions answered within 1 hours.