Fermat’s Theorem, the assignment, utilizesĀ the formula of a^n + b^n = c^n in the form of code. By using a mix of function and math commands, a program can be created where users can input values for the variables to see if the values would work for Fermat’s Theorem or simply not work. This creates a faster way to check what values would work for Fermat’s Theorem in the matter of seconds
Code used to check Fermat’s Theorem:
def check_fermat(a,b,c,n):
if n > 2 and a**n + b**n == c**n:
print “Fermat was right!”
else:
print “No, that doesn’t work.”
a= int(raw_input(‘Enter value for a:’))
b= int(raw_input(‘Enter value for b:’))
c= int(raw_input(‘Enter value for c:’))
n= int(raw_input(‘Enter value for exponent,n:’))
check_fermat(a,b,c,n)