Lucky Number
Sona, a Computer Science aspirant gets an assignment to write a program in Python to find out whether the given number is lucky or not by using lambda function. A number is said to be lucky if the sum of the digits of that number is even.
The function accepts a numeric value and returns 0 or 1. If the return value is 1, then the number is lucky and if the return value is 0, the number is not lucky. Help Sona to write the code.
Note:
- Mandatory to use: lambda function
- If the number is 0 or less, display the message “Invalid Number” and terminate the program.
Sample Input and Output 1:
Enter the Number:191
191 is not lucky
Sample Input and Output 2:
Enter the Number:123
123 is lucky
Sample Input and Output 3:
Enter the Number:0
Invalid Number
Code :-
n=int(input("Enter the Number:")) if n>0: res=lambda n:1 if sum(map(int,str(n)))%2==0 else 0 print((str(n)+' is lucky') if res(n)==1 else (str(n)+" is not lucky")) else: print("Invalid Number")