This is a challenge from Think Python 2nd Edition:
Fermat’s Last Theorem says that there are no positive integers a, b, and c such that aⁿ + bⁿ = cⁿ. for any values of n greater than 2.
Write a function named
check_fermatthat takes four parameters;
n. And that checks to see if Fermat’s theorem holds. If
nis greater than 2 and it turns out to be true that
aⁿ + bⁿ = cⁿthe program should print, “Holy smokes, Fermat was wrong!” Otherwise the program should print, “No, that doesn’t work.”
Write a function that prompts the user to input values for
n, converts them to integers, and uses
check_fermatto check whether they violate Fermat’s theorem.
That's what I've done so far. Are there any improvements I should make? And are there any 'best practices' among programmers that I'm missing? I'm just starting out and I'd like to avoid bad habits.
def check_fermat(a, b, c, n): if n > 2 and a**n + b**n == c**n: print("Holy smokes! Fermat was wrong!") elif n <= 2: print("The exponent should be grater than '2'") else: print("No, that doesn't work.") def check_numbers(): a = int(input("Choose a number for 'a': ")) b = int(input("Choose a number for 'b': ")) c = int(input("Choose a number for 'c': ")) n = int(input("Choose a number for 'n' that's greater than '2': ")) check_fermat(a, b, c, n) check_numbers()