Comprehension is unique feature of python which is not available in c and cpp and all……
Comprehension stands for decrese length of a code as max as possible…….
#code for finding numbers which satisfy these properties : divide by 6=5, divide by 5=4 upto .... 1
#Range is taken from user
#METHOD 1: (Normal)
a=int(input("Enter lower range : "))
b=int(input("Enter higher range : "))
l=[]
for n in range(a,b):
if (n%6==5 and n%5==4 and n%4==3 and n%3==2 and n%2==1):
l.append(n)
print(l)
#METHOD 2: (Comprehension)
print([n for n in range(int(input("Enter lower range : ")),int(input("Enter higher range :"))) if n%6==5 and n%5==4 and n%4==3 and n%3==2 and n%2==1])
#CHALLANGE : try is logic in diff languages as small as possible. Then you will believe how much python can do.
Output>>>
Enter lower range : 1
Enter higher range : 1000
[59, 119, 179, 239, 299, 359, 419, 479, 539, 599, 659, 719, 779, 839, 899, 959]
Sharing is caring!
Great Concept ππ»ππ»ππ» Python is Awesome Language π₯