Before we start our new python project here is another solution for one of the python’s question on codewars. In this example, we need to create a method which will accept a number and returns a list consists of a pair of a number and power that are equal to that input number. For example, the input number is 9, then the number and it’s power which is equals to that input number is [3, 2] because 3 * 3 = 9. If there is no number and power that match the input value then None will be returned. Here is the solution to the above mentioned question.
def isPP(power): for num in range(1, power): for po in range(2, power): if(num ** po == power): return [num, po] return None
The above method is only suitable to solve a number input which is below 1800, the program will become freeze if the number goes beyond that value (depends on the processing power of your own computer). Well, hope you like this quick solution, in the next chapter we will begin our project.
from Planet Python
via read more
No comments:
Post a Comment