-1

My homework is about Fermat's Last Theorem:

1) Write a function named check_fermat that takes four parameters—a, b, c and n—and checks to see if Fermat’s theorem holds.

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.

Here is my code as follows. It works. However, there is always a "None" following the correct answer, such as "Correct! None".

It would be appreciated if you could help me with the problem. Thank you so much.

def check_fermat(a,b,c,n):
    if n > 2:
        print("“Holy smokes, Fermat was wrong!")
    if n == 2  and a**n + b**n == c**n:
        print("Correct!")    
    else:
        print("No, that doesn’t work")


def check_number():
    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: "))
    print(check_fermat(a,b,c,n))

check_number()

1 Answers1

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

This line is what prints None, this is because the return value of check_fermat is None.

The solution is either:

  • only print in check_fermat, remove print from print(check_fermat(a,b,c,n))
  • OR, return a string (or some other sensible return value) from check_fermat, and leave print(check_fermat(a,b,c,n)) as it is.
kutschkem
  • 7,826
  • 3
  • 21
  • 56