我目前正在使用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中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) 我目前正在使用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)
我曾尝试谷歌搜索,但我不是很确定使用的关键词是什么,所以希望能从这里获得帮助.
谢谢.