Fermat’s Last Theorem

def check_fermet(a,b,c,n):
answer = (a ** n) + (b ** n)
print(str(a) + “^” +str(n) + ” + ” + str(b) + “^” + str(n) + ” should be ” + str(c ** n) + “.”)
print(“but it really is…”)
print(answer)

if (answer != (c ** n)):
print(“Fermat was right!”)
if (answer == (c ** n)):
print(“Holy smokes, Fermat was wrong!”)
print(“Fermat’s Last Theorem states that no three positive integers a, b, and c can satisfy the equation a^n + b^n = c^n\nfor any integer value of n greater than two.\nLets test it out!”)
answer1 = int(input(“Assign a number to the variable a\n>>>”))
answer2 = int(input(“Assign a number to the variable b\n>>>”))
answer3 = int(input(“Assign a number to the variable c\n>>>”))
answer4 = int(input(“Assign a number to the variable n\n>>>”))
check_fermet(answer1,answer2,answer3,answer4)

 

Fermat’s Last Theorem states that no three positive integers a, b, and c can satisfy the equation an + bn = cn for any integer value of n greater than two. I created a program that tested if his theorem was true. First I create a function and named it check_fermet(a,b,c,n). Then I assigned the variable name “answer” equal to the answer of the equation (a ** n) + (b ** n). Next I made the program print the equation with the input of the user into its respectable place. In order to do that, I must allow the user to assign a number to the variables. So I used integer(input()) and assign a variable name for a,b,c and n. Then I placed the variable names for a,b,,c and n into the function of check_fermat. I used the “if” statement so that if the “answer” is not equal to c ** n, then it will print “Fermat was right!” and I used another if statement where if the answer is equal to c ** n, then it will print “Holy smokes, Fermat was wrong!” In conclusion, I learned that Fermat’s theory was correct with the help of utilizing functions and conditionals.