Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def checkfermat(a,b,c,n):
- try:
- a = int(a)
- except ValueError:
- print "a is not a proper integer"
- try:
- b = int(b)
- except ValueError:
- print "b is not a proper integer"
- try:
- c = int(c)
- except ValueError:
- print "c is not a proper integer"
- try:
- n = int(n)
- except ValueError:
- print "n is not a proper integer"
- print "a**n + b**n = ",a**n + b**n,"c**n is:",c**n
- if a**n + b**n == c**n:
- print "This case proves fermat's theorem wrong!"
- else:
- print "The theory holds."
- supplyargs(a,b,c,n)
- def supplyargs(a='4',b='5',c='6',n='3'):
- 'supply args for checking fermats theorem'
- print "values are a:",a,"b:",b,"c:",c,"n:",n
- string = raw_input("type a,b,c, or n followed by a dash and the number, or type 'ready':")
- t = string[0]
- if string == "ready":
- checkfermat(a,b,c,n)
- if t != "a" and t != "b" and t != "c" and t != "n" and string != "ready":
- print "Error: the first character was neither a,b,c or n."
- supplyargs(a,b,c,n)
- if string != "ready":
- try:
- t = string[1]
- except IndexError:
- print "The string is not long enough."
- supplyargs(a,b,c,n)
- if t != "-":
- print "Error: the second character was not a dash(-)."
- supplyargs(a,b,c,n)
- else:
- print "running else"
- t1 = string[0]
- t2 = string[2:]
- if t1 == 'a':
- a = t2
- if t1 == 'b':
- b = t2
- if t1 == 'c':
- c = t2
- if t1 == 'n':
- n = t2
- supplyargs(a,b,c,n)
- supplyargs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement