MrWallace
MrWallace

Reputation: 37

Converting cubic cm to litres in python

I want to write a function that when I input the dimensions of a truncated cone (a cup) and an amount of liquid in litres returns how many of these cups can be filled up with the amount of liquid.

def number_of_cups(bottom_radius, top_radius, height, litres_of_liquid):

    volume = math.pi / 3 * height * (bottom_radius**2 + top_radius * bottom_radius +  top_radius**2)

    return int(filled_cup)

This is as far as I have got, I don't understand how I convert the volume in cm^3 to litres using Python. How would I incorporate the conversion of 1L = 1000 into the code

I am running Python 3 to clear up any version confusion.

Any help is much obliged.

Upvotes: 0

Views: 1050

Answers (2)

lvc
lvc

Reputation: 35089

If you don't know the conversion factors between units, you can look them up online. I Googled "converting volume to capacity", and came up with this handy tool, which tells me that 1 cubic centimeter is 0.001 litres. So, multiple your cc result by that number (or, equivalently, but possibly more accurately in the face of binary floating point numbers, divide by 1000) and you have your answer.

Upvotes: 0

icktoofay
icktoofay

Reputation: 129109

There are 1000 cubic centimeters in a liter, so divide by 1000.

Upvotes: 2

Related Questions