Python - How to Write a function

How to Write a function kinda_format ( ) that take three arguments (each of which positive int ) - a,b,c- and tests whether the equality a^n +b^n=c^n holds for each n{2,3,...,10}. The function should return false if the equality does not hold for any value of n in the given range, and if there is a value of n for which the equality holds, the lowest such value (as in int)

Questions by Jeffsdf

Showing Answers 1 - 3 of 3 Answers

Hema

  • Jan 3rd, 2015
 

Python code attached

Code
  1. def  kinda_format(a,b,c):

  2.    

  3.      for i in range(1,10):

  4.          if( (a**i + b**i) == (c**i)):

  5.              flag=1

  6.              return(i,1)

  7.            

  8.      return(-1,0)

  9.  

  10.  

  11. # Main program

  12. (index,flag) = kinda_format(5,5,15)    

  13. if(flag == 1):

  14.     print " It has the equality " + str (index)

  15. else:

  16.     print  "It does not have equality "

  17.      

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions