+ 1

PYTHON help!!!

I am tring to write a single line code which looks something just like this code type : is x>2 when x in range (5,10) or code type : print ((x>2) when x=3) I am trying to get a boolean return ie (True or False) from my code checking the codition applied but I don't know how I can write this as a python code Please help.

17th May 2018, 6:22 PM
VISHNU P.S
VISHNU P.S - avatar
3 Answers
+ 2
'''This code returns True for all Even numbers larger than 2.''' print((lambda x: x>2 and x%2==0)(int(input())))
17th May 2018, 6:54 PM
Louis
Louis - avatar
+ 1
The Examples you give does not make sense from a logic perspective. The first one says: x>2 when in range(5,10) but all items in range(5,10) are larger than 2, so the first part x>2 does not add value. The second one says x>2 when x==3 (remember double equals to check equality ==) since 3 is larger than 2 the first part x>2 adds no value. Have a look a Karnaugh graphs. https://en.m.wikipedia.org/wiki/Map_K
17th May 2018, 7:24 PM
Louis
Louis - avatar
0
I don't Want my codes to give any integer value . all I am trying to do is to get a booking valid like true or false .. eg when x is in the range 5 to 10 the expression x>2 is always true ..I want to kNow how to write Python code for this
18th May 2018, 2:48 AM
VISHNU P.S
VISHNU P.S - avatar