Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
725 B
2
Indexable
Never
def check_fermat(a, b, c, n):
    # check if n is greater than 2
    if n > 2:
        # calculate the left and right sides of the equation
        left = a ** n + b ** n
        right = c ** n

        # check if the equation holds
        if left == right:
            # print that Fermat was wrong
            print('Holy smokes, Fermat was wrong!')
        else:
            # print that the equation does not hold
            print('No, that doesn’t work.')
    else:
        # print that n must be greater than 2
        print('n must be greater than 2.')

# call the function to check Fermat's theorem for several values
check_fermat(1, 2, 3, 3)
check_fermat(1, 2, 3, 4)
check_fermat(1, 2, 9, 3)
Leave a Comment