-1

Can Any one correct it I kinda liked it but it's not working

f=lambda x:"Not Weird" if (x%2==0 and (1<x<6 or x>20)) else "weird"
print(f)

And I know I can do it with If else statement easily but it's just for learning purpose and so if you can improvise in the same direction then please enlighten me.

Nishant
  • 20,354
  • 18
  • 69
  • 101
  • A lambda is like a function, you need to call it with `f(...)` for it to produce anything meaningful – rdas Feb 11 '21 at 12:41
  • Try `print(f(10))` – Sociopath Feb 11 '21 at 12:41
  • 1
    I know it's just for learning, but just to mention it's against PEP8 recommendations - _Always use a `def` statement instead of an assignment statement that binds a `lambda` expression directly to an identifier_ – buran Feb 11 '21 at 12:44
  • You failed to ask a question... What is wrong with your code? – Tomerikoo Feb 11 '21 at 12:54

1 Answers1

0

Fire the lambda using ()

f=lambda x:"Not Weird" if (x%2==0 and (1<x<6 or x>20)) else "weird"
print(f(1))
weird
Epsi95
  • 8,832
  • 1
  • 16
  • 34