exmaple 1:-
def test_range(n):
if n in range(10,20):
print( "Number %s is in the range"%str(n))
else :
print("The number is outside the given range.")
test_range(15)
output:-
Number 15 is in the range
>>>
example 2:-
def test_range(n):
if n>= 10 and n>= 100:
print ("you have to pay 5% taxes")
test_range(120)
output:-
you have to pay 5% taxes
>>>
example 3:-
# Python program to count the
# number of numbers in a given range
# using traversal and multiple line code
def count(list1, l, r):
c = 0
# traverse in the list1
for x in list1:
# condition check
if x>= l and x<= r:
c+= 1
return c
# driver code
list1 = [10, 20, 30, 40, 50, 40, 40, 60, 70]
l = 40
r = 80
print(count(list1, l, r))
output:-
6
>>>
Post a Comment
If you have any doubts, Please let me know
Thanks!