Fermat’s Theorem

check-fermatfirst

In this first section of code the function “check_fermat” is defined to create an equation that represents Fermat’s theorem.

check-fermat

This second piece of code is the end result of the program, where a function called “check_numbers” is defined to rely on the user’s input. This allows the function to be checked with any combination of numbers rather than a few predetermined ones. The code also ensures that the input must be integers by using the command “int.”

check-fermat-run

This last picture is the result when the code from the second picture is run. The user is asked to input a value for each of the four variables, a, b, c, and n. Following that the program prints one of two responses, “Fermat was right”, or “No, these numbers don’t work” as you can see above.