0

I am trying to create a function that goes like this:

def ratio_transform(n, h, nh):
     ...

In other words, your fraction is n / h and the returned value is x / nh

For example, I want to convert 5 / 100 to x / 1000 (n is 5, h is 100 and nh is 1000)

My code goes:

def ratio_transform(n, h, nh):
    return (n / h) * nh

But ratio_transform(5, 100, 1000) always returns 0.0, when it should return 0.5

Is it a logic error, or a data type error?

R Harrington
  • 253
  • 2
  • 10

1 Answers1

1
def ratio_transform(n, h, nh):
    return (n / float(h)) * nh
Miloslav Číž
  • 557
  • 4
  • 18