在python 3.4的全局部分中的main函数中调用函数

时间:2018-06-19 18:35:50

标签: python python-3.x

chunk {8} account-account-module-ngfactory.3381d22a1e8d5db6b823.js (account-account-module-ngfactory) 70.3 kB  [rendered]
chunk {scripts} scripts.29cb0c319e11420627c6.js (scripts) 876 kB  [rendered]
chunk {0} common.e58351c45cec4bb0f84d.js (common) 17.5 kB  [rendered]
chunk {1} account-account-module-ngfactory~finder-finder-module-ngfactory~lister-lister-module-ngfactory.9fd06129611a0271f9ea.js (account-account-module-ngfactory~finder-finder-module-ngfactory~lister-lister-module-ngfactory) 26 kB  [rendered]
chunk {2} finder-finder-module-ngfactory~lister-lister-module-ngfactory~screens-screens-module-ngfactory.d512470383c55e2004b8.js (finder-finder-module-ngfactory~lister-lister-module-ngfactory~screens-screens-module-ngfactory) 68.2 kB  [rendered]
chunk {3} lister-lister-module-ngfactory~monitor-monitor-module-ngfactory.00e81bc0649f067026a6.js (lister-lister-module-ngfactory~monitor-monitor-module-ngfactory) 228 kB  [rendered]
chunk {4} monitor-monitor-module-ngfactory.145e0aaf56cca28ab92d.js (monitor-monitor-module-ngfactory) 238 kB  [rendered]
chunk {5} lister-lister-module-ngfactory.00baef5ecda629c1924b.js (lister-lister-module-ngfactory) 1.03 MB  [rendered]
chunk {6} finder-finder-module-ngfactory.0c67cb70a42e4e1248fd.js (finder-finder-module-ngfactory) 234 kB  [rendered]
chunk {7} dashboard-dashboard-module-ngfactory.0a194d0dd1e6b3d22216.js (dashboard-dashboard-module-ngfactory) 1.49 kB  [rendered]
chunk {9} login-login-module-ngfactory.3803a9fde37726d2fcb1.js (login-login-module-ngfactory) 97.3 kB  [rendered]
chunk {10} screens-screens-module-ngfactory.517275ed05ee9a3474b9.js (screens-screens-module-ngfactory) 200 kB  [rendered]
chunk {11} auth-auth-module-ngfactory.9b8c7640150610ba12dc.js (auth-auth-module-ngfactory) 62 kB  [rendered]
chunk {12} runtime.b75eb3e8646a750ee46a.js (runtime) 2.68 kB [entry] [rendered]
chunk {13} styles.80497f4105b47590510a.css (styles) 80.6 kB [initial] [rendered]
chunk {14} polyfills.c428b26f0c9cd88ad9e2.js (polyfills) 64.3 kB [initial] [rendered]
chunk {15} main.bfa19806e0940a6dbd7e.js (main) 1.06 MB [initial] [rendered]

错误是:

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)

2 个答案:

答案 0 :(得分:2)

问题是variable scopec在函数外部不存在

您可能想要尝试为函数提供正确的参数,尽管如果您确实有一个c变量,则会得到一个不同的错误。

import math
def nthroot(x,n):
    return math.pow(x,1/n)

a=float(input("enter the value of x"))
b=float(input("enter the value of n"))

d=nthroot(a, b)  # See here
print(d)

如果将“ x”输入的值分配给名为x的实际变量也可能有帮助,以便您了解其用途是什么

答案 1 :(得分:1)

由于您创建了一个带有两个参数的函数,因此在调用它时应该传递2个参数。您的代码应类似于-

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(a,b)
print (d)

现在,我们正在将从用户获取的两个值传递给函数(此处为a和b)。 该函数正在计算结果,将结果存储在c中,然后返回c。我们将此结果存储在d中。最后我们要打印d。