有人能解释一下我做错了什么吗
我的代码显示为x not defined
。我要做的是在add1
中得到x
的结果,并将其传递给doub
函数。我已经尽可能多地搜索和阅读了这篇文章,我知道我遗漏了一些东西,所以请给我指出正确的方向
def main():
value = (int)(input('Enter a number '))
add1(value)
doub(x)
def add1(value):
x = value + 1
return x
def doub (x):
return x*2
main()
Tags:
试试这个:
x
只存在于add1
函数中。您的main
函数只知道调用add1返回的值,而不是它以前存储的变量名。您需要将该值赋给一个变量,并将其传递到doub
:还要注意,Python不是C;没有打字这回事
int
是对值调用的函数:相关问题 更多 >
编程相关推荐