#5 Program Fermat’s Last Theorem

#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.
#First problem.
#1. Write a function named check_fermat that takes four parameters—a, b, c and n
#and that checks
#to see if Fermat’s theorem holds. If n is greater than 2 and it turns out
#to be true
#that an + bn = cn the program should print, “Fermat was right!”
#Otherwise the program should print, “No, that doesn’t work.”
#2. Write a function that prompts the user to input values for a, b, c and n,
#converts them to integers, and uses check_fermat to check whether
#they violate Fermat’s theorem.

 

import math

def check_fermat(a, b, c, n):

if n > 2 and a**n + b**n == c**n:
return “Fermat was right!”
else:
return “No, that doesn’t work.”

print (check_fermat(2, 3, 4, 10))

 

Now if we are asking the user to input the data for the variable we program it like this:

 

import math

def check_fermat(a, b, c, n):

if n > 2 and a**n + b**n == c**n:
return “Fermat was right!”
else:
return “No, that doesn’t work.”
a = float(input(‘please enter the a value for the theorem: ‘))
b = float(input(‘please enter the b value for the theorem: ‘))
c = float(input(‘please enter the c value for the theorem: ‘))
n = float(input(‘please enter the n value for the theorem: ‘))

print (check_fermat(a, b, c, n))