문제 설명
여러 함수의 변수를 다른 함수로 사용 (Use variables from multiple functions into another function)
func1 및 func2라는 두 개의 함수가 있다고 가정해 보겠습니다.
def func1():
a=1
return a
def func2():
b=2
return b
def func3():
x=a+b
return x
func3()
이제 func3을 호출하면 오류가 반환됩니다. 문제가 어디에 있습니까? 방금 파이썬을 배우기 시작했는데 문제를 해결할 수 없는 것 같습니다.
참조 솔루션
방법 1:
The variables a
and b
do not exist inside func3
. I suggest you pass them as parameters to the function
방법 2:
Its difficult to see what you are after, but for the code you have posted this is a solution:
def func1():
a = 1
return a
def func2():
b = 2
return b
def func3():
x = func1() + func2()
return x
func3()
(by Farhan Bin Amin、Azamat Galimzhanov、quamrana)