jeudi 22 juillet 2021

Python Function Simplifier Buggy

This is the script I was making to simplify functions.

def fraction(a=None, b=None):
    if a is None:
        a = int(input("Enter the value of a "))
    if b is None:
        b = int(input("Enter the value of b "))
    if a > b:
        small = b
    else:
        small = a
        for i in range(1, small+1):
            if((a % i == 0) and (b % i == 0)):
                gcf = i
    print(a//i, "/", b//i)
fraction()

When run, it only works on very specific inputs (eg. 20/50) but does not work on most negative inputs, when a is bigger than b and fractions like 52/88.

Aucun commentaire:

Enregistrer un commentaire