综合编程

Return the list of the number and its power with python

微信扫一扫,分享到朋友圈

Return the list of the number and its power with python
0

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.

阅读原文...


Avatar

提供紧急避孕药的自动售货机在美国大学校园悄然兴起

上一篇

JAVA_HOME indicates the wrong location

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Return the list of the number and its power with python

长按储存图像,分享给朋友