如何在不询问输入两次的情况下将一个函数的输入传递给另一个函数。我的代码如下所示:
def function():
signal_0 = 1
signal_1 = input("0 or 1?")
select = 0
output = (not select and signal_0) or (select and signal_1)
return output, select
def connection(func):
eingang = func()[0]
return eingang
print(function())
print(connection(function))
我想发生的是,print(connection(function))
不再询问input("0 or 1?")
。
应该采取被要求输入function
已经如此,如果我有1作为输入signal_1 = 1
的connection(function)
一种简单的方法是:
def function(flag=1):
signal_0 = 1
if flag==0:
signal_1 = input("0 or 1?")
select = 0
output = (not select and signal_0) or (select and signal_1)
return output, select
def connection(func):
eingang = func()[0]
return eingang
print(function(0))
print(connection(function))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句