Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I need help with floats and int
#1
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)
Larz60+ wrote Aug-25-2017, 04:18 PM:
Please use code tags for your code. I added them for you this time
see BBCODE
Quote
#2
In what way is it not already correct?  What's your current output, your expected output, and what (if any) errors are you getting?
Quote
#3
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#4
(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.
Quote
#5
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)
Ofnuts likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  def functions and floats alwillia 3 844 May-26-2018, 07:31 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)