Python Forum

Full Version: I need help with floats and int
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on this for my intro to programming class. The cpcf is 1.2 the width is 20, the length is 30, and the depth is 10. Please help me and tell me what I am missing to make this work.

#this program figures the cost for filling a public pool
#Caleb
cpcf = float(input("Enter how much the city charges for a cubic foot of water"))
PoolWidth = float(input("Enter the width of the pool"))
PoolLength = float(input("enter the length of the pool"))
PoolDepth = float(input("Enter how deep the pool is"))
Volume = PoolWidth * PoolLength * PoolDepth
cost = cpcf * Volume
print("the cost of filling the pool is: " + cost)
In what way is it not already correct?  What's your current output, your expected output, and what (if any) errors are you getting?
In the future, please put your code in python tags, see the BBCode link in my signature below. Also, it helps a lot if you give us the full text of the error you are getting.

In this case, you are trying to add a float to a string on the last line, which you can't do. You need to convert cost to a string. The easiest way to do this is with str(cost)

If you have been taught the format method of strings, you should review that. It will give you more control over how the output is formatted.
(Aug-25-2017, 04:20 PM)ichabod801 Wrote: [ -> ]In the future, please put your code in python tags, see the BBCode link in my signature below. Also, it helps a lot if you give us the full text of the error you are getting.

In this case, you are trying to add a float to a string on the last line, which you can't do. You need to convert cost to a string. The easiest way to do this is with str(cost)

If you have been taught the format method of strings, you should review that. It will give you more control over how the output is formatted.

Thank you so much. We have not been taught much to be honest.
Another solution to your problem is to replace the "+" in the last line to a ",". That way, you are not trying to add a string and a float together, but just printing them out seperately.

print("the cost of filling the pool is: ",cost)