Creating def functions

guys could you create some simple fraction functions in python for me im in a bit of a bind and could really use your help this is essential to a project im working on and I just dont now what to do it is due in two hours
a function that takes a fraction list and reduces that fraction to lowest terms, returning the appropriate fraction list. For example, reduce([4,6]) would return [2,3].

a function that takes a string representing a fraction and returns the corresponding fraction list in lowest terms. For example, makeFraction(‘3/4’) would return [3, 4]

a function that takes two fraction lists and returns True if the fractions are the same and False otherwise

a function that takes two fraction lists and returns a list representing the sum of those fractions in lowest terms.

Something like this?

def frac(f):
    x = (f[0]/f[1])
    c=1
    while not (x*c).is_integer():
        c+=1
    return [x*c, c]

def makeFraction(x):
    return frac([x, 1])

print(frac([20, 35]))
print(makeFraction(20/35))

Edit:

Oh sorry, missed that, hope it went well!

As in your other thread on this, ask us where your stuck, dont ask us to do your homework for you. Everyone's more than willing to help you learn, but you wont learn if you just want other people to do it for you.

1 Like