'TypeError <lambda> missing 1 required positonal argument
For school I have to finish some exercises. I keep getting this error:
TypeError <lambda> () missing 1 required positional argument: 'f2'
and I have no idea what I'm doing wrong. This code is supposed to do multiple things, namely:
- Function
ORtakes two functions as inputs and returns alambdawhich, given one input, applies both functions to such input and computes the 'or' of the results. - Function
ORtakes two functions as inputs and returns alambdawhich, given one input, applies both functions to such input and computes the 'or' of the results. - Function
ORtakes two functions as inputs and returns alambdawhich, given one input, applies both functions to such input and concatenates the results. f1is alambdathat checks if the input is odd.f2is alambdathat checks if the input is positive.surroundis alambdawhich given a number, returns a string made by that number surrounded by square brackets.toStaris alambdawhich given any input returns the string'*'.
This is my code:
def OR(f2, f1):
return lambda f1, f2 : True if (f1 or f2) else False
def AND(f1, f2):
return lambda f1, f2 : True if f1 and f2 else False
def CONCAT(f, g):
return lambda f, g : f + g
f1 = lambda f1: False if f1 % 2 == 0 else True
f2 = lambda f2: True if f2 > 0 else False
surround = lambda c : '[' + str(c) + ']'
toStar = lambda c : str(c) + '*'
a = 7
b = 9
c = 5
res1 = OR(f1, f2)(a)
res1b = AND(f1, f2)(a)
res2 = OR(f1, f2)(b)
res2b = AND(f1, f2)(b)
res3 = CONCAT(surround, toStar)(c)
res4 = CONCAT(toStar, surround)(c)
print()
Does anybody have a clue what I'm doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
