Reputation: 45
I'm working on a python exercise that requires getting the string return values of function. Here is the sample code that is related to the one I'm currently working on.
def main():
x = 'the quick'
y = 'brown fox'
return x, y
def function1(x, y):
if x == 'the quick' and y == 'brown fox':
return 'jump'
else:
return 'lazy'
def function2():
if a == 'jump':
print('good boy')
else:
print('bad boy')
function2(*function1(*main()))
I'm getting positional argument error. How to return the string properly for other function?
Upvotes: 3
Views: 191
Reputation: 88
At first you have to specify parameters for function2: I guess you want to define function2 in this way:
def function2(a):
if a == 'jump':
print('good boy')
else:
print('bad boy')
And you may want funtion2 output 'good boy', In this way, you could try:
function2(function1(*main()))
Which will give the output as you want.
Upvotes: 0
Reputation: 2534
You have not specified that Function2()
takes any arguments.
I got your code to run by specifying four function arguments (while only using one):
def main():
x = 'the quick'
y = 'brown fox'
return x, y
def function1(x, y):
if x == 'the quick' and y == 'brown fox':
return 'jump'
else:
return 'lazy'
def function2(a, b, c, d):
if a == 'jump':
print('good boy')
else:
print('bad boy')
function2(*function1(*main()))
This returns:
bad boy
Upvotes: 6