In [1]:
def if_test(num):
if num > 100:
print('100 < num')
elif num > 50:
print('50 < num <= 100')
elif num > 0:
print('0 < num <= 50')
elif num == 0:
print('num == 0')
else:
print('num < 0')
In [2]:
if_test(1000)
In [3]:
if_test(70)
In [4]:
if_test(0)
In [5]:
if_test(-100)
In [6]:
def if_test2(num):
if 50 < num < 100:
print('50 < num < 100')
else:
print('num <= 50 or num >= 100')
In [7]:
if_test2(70)
In [8]:
if_test2(0)
In [9]:
def if_test_in(s):
if 'a' in s:
print('a is in string')
else:
print('a is NOT in string')
In [10]:
if_test_in('apple')
In [11]:
if_test_in('melon')
In [12]:
if 10:
print('True')
In [13]:
if [0, 1, 2]:
print('True')
In [14]:
print(bool(10))
In [15]:
print(bool(0.0))
In [16]:
print(bool([]))
In [17]:
print(bool('False'))
In [18]:
def if_test_list(l):
if l:
print('list is NOT empty')
else:
print('list is empty')
In [19]:
if_test_list([0, 1, 2])
In [20]:
if_test_list([])
In [21]:
def if_test_and_not(num):
if num >= 0 and not num % 2 == 0:
print('num is positive odd')
else:
print('num is NOT positive odd')
In [22]:
if_test_and_not(5)
In [23]:
if_test_and_not(10)
In [24]:
if_test_and_not(-10)
In [25]:
def if_test_and_not_or(num):
if num >= 0 and not num % 2 == 0 or num == -10:
print('num is positive odd or -10')
else:
print('num is NOT positive odd or -10')
In [26]:
if_test_and_not_or(5)
In [27]:
if_test_and_not_or(10)
In [28]:
if_test_and_not_or(-10)
In [29]:
def if_test_and_backslash(num):
if num >= 0 \
and not num % 2 == 0:
print('num is positive odd')
else:
print('num is NOT positive odd')
In [30]:
if_test_and_backslash(5)
In [31]:
def if_test_and_brackets(num):
if (num >= 0
and not num % 2 == 0):
print('num is positive odd')
else:
print('num is NOT positive odd')
In [32]:
if_test_and_brackets(5)