小编Joh*_*ohn的帖子

找出a是否是b的幂

我目前正在使用singpath.com来练习我的python,但是我遇到了一个问题:

数字a是b的幂,如果它可被b整除,a/b是b的幂.编写一个名为is_power的函数,它接受参数a和b,如果a是b的幂,则返回True.

def is_power(a,b):
    c = a/b
    if (((a%b) == 0) and ((c%b) == 0)):
        return True
    else:
        return False 
Run Code Online (Sandbox Code Playgroud)

以上是我的解决方案,但系统提示我概括我的解决方案.谁能告诉我我的解决方案有什么问题?

python

6
推荐指数
2
解决办法
7880
查看次数

sqrt:ValueError:数学域错误

在python中distance ValueError: math domain error使用sqrt函数时,我遇到了" " 的问题.

这是我的代码:

from math import sqrt

def distance(x1,y1,x2,y2):
    x3 = x2-x1
    xFinal = x3^2
    y3 = y2-y1
    yFinal = y3^2
    final = xFinal + yFinal
    d = sqrt(final)
    return d
Run Code Online (Sandbox Code Playgroud)

python math

4
推荐指数
2
解决办法
3万
查看次数

Python:TypeError:只需要1个参数(给定2个)

我目前正在使用singpath.com练习我的python,但是我遇到了一个问题:

预期的结果是:

>>>CurryPuff(3) 
3.60 
>>>CurryPuff(3,'Fish') 
4.2
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

def CurryPuff(x,typePuff):

   if(typePuff==''):

      return x*1.2

   if(typePuff=='Fish'):

      return x*1.4
Run Code Online (Sandbox Code Playgroud)

但它给了我这个错误:

TypeError: CurryPuff() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)

我曾尝试谷歌搜索,但我不是很确定使用的关键词是什么,所以希望能从这里获得帮助.

谢谢.

python

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×3

math ×1