Advertisement
Guest User

checking fermat's theorem

a guest
Nov 6th, 2011
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. def checkfermat(a,b,c,n):
  2.     try:
  3.         a = int(a)
  4.     except ValueError:
  5.         print "a is not a proper integer"
  6.  
  7.     try:
  8.         b = int(b)
  9.     except ValueError:
  10.         print "b is not a proper integer"
  11.  
  12.     try:
  13.         c = int(c)
  14.     except ValueError:
  15.         print "c is not a proper integer"
  16.  
  17.     try:
  18.         n = int(n)
  19.     except ValueError:
  20.         print "n is not a proper integer"
  21.     print "a**n + b**n = ",a**n + b**n,"c**n is:",c**n
  22.     if a**n + b**n == c**n:
  23.         print "This case proves fermat's theorem wrong!"
  24.     else:
  25.         print "The theory holds."
  26.     supplyargs(a,b,c,n)
  27.  
  28. def supplyargs(a='4',b='5',c='6',n='3'):
  29.     'supply args for checking fermats theorem'
  30.     print "values are a:",a,"b:",b,"c:",c,"n:",n
  31.     string = raw_input("type a,b,c, or n followed by a dash and the number, or type 'ready':")
  32.     t = string[0]
  33.     if string == "ready":
  34.        
  35.         checkfermat(a,b,c,n)
  36.     if t != "a" and t != "b" and t != "c" and t != "n" and string != "ready":
  37.         print "Error: the first character was neither a,b,c or n."
  38.         supplyargs(a,b,c,n)
  39.     if string != "ready":  
  40.         try:
  41.             t = string[1]
  42.         except IndexError:
  43.             print "The string is not long enough."
  44.             supplyargs(a,b,c,n)
  45.         if t != "-":
  46.             print "Error: the second character was not a dash(-)."
  47.             supplyargs(a,b,c,n)
  48.         else:
  49.             print "running else"
  50.             t1 = string[0]
  51.             t2 = string[2:]
  52.             if t1 == 'a':
  53.                 a = t2
  54.             if t1 == 'b':
  55.                 b = t2
  56.             if t1 == 'c':
  57.                 c = t2
  58.             if t1 == 'n':
  59.                 n = t2
  60.             supplyargs(a,b,c,n)
  61.  
  62. supplyargs()
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement