import math
def nthroot(x,n):
c=math.pow(x,1/n)
return(c)
a=float(input("enter the value of x"))
b=float(input("enter the value of n"))
d=nthroot(c)
print (c)
错误是:
Traceback (most recent call last):`
File "C:/Users/Soham Pal/Desktop/dec_to_octal.py", line 8, in <module>
d=nthroot(c)
NameError: name 'c' is not defined
问题是variable scope
c
在函数外部不存在您可能希望尝试为函数提供正确的参数,但是如果确实有
c
变量,则会出现不同的错误如果您将“x”输入的值赋给一个名为
x
的实际变量,这样您就可以理解它的用途,这可能会有所帮助因为您创建了一个接受两个参数的函数,所以在调用它时应该传递两个参数。你的代码应该是-
现在,我们将从用户获取的两个值传递给函数(这里是a和b)。 函数用于计算结果,将结果存储在c中,并返回c。我们将这个结果存储在d中。最后我们打印d
相关问题 更多 >
编程相关推荐