Read a number from the user. Check whether it is zero or non-zero using the lambda function and print the output as either ZERO or NON-ZERO. Sample Input5Sample OutputNON-ZERO
Question
Read a number from the user. Check whether it is zero or non-zero using the lambda function and print the output as either ZERO or NON-ZERO. Sample Input5Sample OutputNON-ZERO
Solution
Sure, I can help you with that. Here are the step-by-step instructions to solve the problem:
- Prompt the user to enter a number.
- Read the input number from the user.
- Define a lambda function to check whether the number is zero or non-zero. The lambda function should take the input number as a parameter and return "ZERO" if the number is zero, and "NON-ZERO" if the number is non-zero.
- Use the lambda function to check the input number.
- Print the output based on the result of the lambda function. If the lambda function returns "ZERO", print "ZERO". If the lambda function returns "NON-ZERO", print "NON-ZERO".
Here is the code in Python:
# Step 1: Prompt the user to enter a number
number = int(input("Enter a number: "))
# Step 3: Define a lambda function to check whether the number is zero or non-zero
check_zero = lambda num: "ZERO" if num == 0 else "NON-ZERO"
# Step 4: Use the lambda function to check the input number
result = check_zero(number)
# Step 5: Print the output based on the result of the lambda function
print(result)
When you run this code and enter a number, it will check whether the number is zero or non-zero using the lambda function and print the output as either "ZERO" or "NON-ZERO".
Similar Questions
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
Write a program to check whether a number is positive or negative. Take an integer, num, as an input from the console using input() function and print the result to the console as shown in the sample test case. Sample Input and Output 1: num: 02 positive Sample Input and Output 2: num: -52142 negative Sample Input and Output 3: num: 0 zero
Given an integer input , whether the given input is "Positive" or "Negative" or "Zero" and print the corresponding messageInput Format:Enter an integer as a input Output Format: Print the output as "Negative" or "Positive" or "Zero"Constraints:1 <= INPUT <= 10^15Sample Input 1:-98Sample Output 1:NEGATIVESample Input 2:0Sample Output 2:ZERO
Read an integer natural number N. Print the range of numbers(1 to N) followed by the string 'VIT' if the number is a multiple of 5 else print 'VIT'.Sample Input5Sample OutputVITVITVITVIT5 VIT
Write a program that takes a number 𝑁N as the input, and prints it to the output.Input FormatThe only line of input contains a single integer.Output FormatOutput the answer in a single line.Constraints0≤𝑁≤1050≤N≤10 5 Sample 1:InputOutput123123
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.