Cannot concatenate ‘str’ and ‘float’ objects?

All floats or non string data types must be casted to strings before concatenation

This should work correctly: (notice the str cast for multiplication result)

easygui.msgbox=("You need "+ str(3.14*(float(radius)**2) * float(height)) + "gallons of water to fill this pool.")

straight from the interpreter:

>>> radius = 10
>>> height = 10
>>> msg = ("You need "+ str(3.14*(float(radius)**2) * float(height)) + "gallons of water to fill this pool.")
>>> print msg
You need 3140.0gallons of water to fill this pool.

Leave a Comment

error code: 523