Read a number from the user. Check whether it is odd or even using lambda function and print the output as either ODD or EVEN. Sample Input5Sample OutputODD
Question
Read a number from the user. Check whether it is odd or even using lambda function and print the output as either ODD or EVEN.
Sample Input
5
Sample Output
ODD
Solution
Sure, here are the steps to solve the problem:
- Read a number from the user.
- Define a lambda function to check whether the number is odd or even. The lambda function can be written as:
is_even = lambda num: num % 2 == 0
- Use the lambda function to check whether the number is even or odd. You can do this by calling the lambda function with the input number as an argument.
is_even_result = is_even(number)
- Print the output based on the result of the lambda function. If the result is True, print "EVEN". Otherwise, print "ODD".
if is_even_result: print("EVEN") else: print("ODD")
By following these steps, you can determine whether a given number is odd or even using a lambda function and print the output accordingly.
Similar Questions
Write an HTML and JavaScript program which accepts N as input and print N is oddor even number
Even numbersWrite a Python program to print the even numbers from a list.Sample Test Cases
Write the program to enter integer elements from user in singly linked list. User can enter both andeven values.
def even_odd_decimal(num): if num%1!=0: return num "is decimal" elif num%2==0: return num "is even" else: return num "is odd"
Create a program in Java that will accept two integers. If the sum of the integers is odd, display the higher integer, else, display the lower integer.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.