- 1

Is this correct lambda expression to find a even or odd number

number = int(input("Enter a number >> ")) odd_even = lambda : "Even Number" if number % 2 == 0 else "Odd Number" print(odd_even())

6th Jan 2019, 9:17 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
4 ответов
+ 2
Why don't you put your function into Code Playground and test it?
6th Jan 2019, 9:25 PM
HonFu
HonFu - avatar
+ 5
🄼🄼🄷🄺 Yes the lambda expression is correct. But I would say it is better if you pass 'number' as a parameter to the lambda function: https://code.sololearn.com/cPT7YbpRZfzO/?ref=app
6th Jan 2019, 10:28 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 4
Four downvotes? For my answer? I thought my comment to be the most natural recommendation, and there was definitely no harm intended! Normally you'd put a code here after you tried it but it puts out awkward results or gives errors and you don't understand what's wrong. Then you'd ask: 'What's wrong with this?' But 'is this lambda expression correct?' is easily to be answered by just feeding numbers and check if they get evaluated correctly.
6th Jan 2019, 10:19 PM
HonFu
HonFu - avatar
0
n=int(input()) odd_even=lambda n:"Even number" if(n%2==0) else "Odd number" print(odd_even(n))
6th Feb 2020, 8:43 AM
kavya lucky
kavya lucky - avatar