Convert distances in python

Viewed 34

Im looking to convert horse racing distances in python. For example i want to convert '7F' to 1400m as 1 furlong is 200m. The same goes for miles, 1m needs to be 1600m. so when there is 1m 1/2f i want to convert that to 1700m.

can anyone help me figure this out please?

2 Answers

I'm relatively new to Python, but this should work. It prints the total distance in meters and takes in user input about the # of furlongs and # of miles.

def total_meters(furlong,miles):
    total = ((furlong * 200) + (miles * 1600))
    print(f'Total distance in meters is: {total}')


a = float(input("Enter # of furlongs:"))
b = float(input("Enter # of miles:"))

total_meters(a,b)

Well you just make a function that can convert your length. Simply take the equation and translate that in python:

def F_to_m(l):
   """ returns the converted length from F to m using l * length in meter / length in F """

You should be able to figure out what formula to use in each function. Just use a proportionality table to know what you multiply and divide by to find the final length.

Related