Report Bug

Qus

Write a list comprehension equivalent for the Python code shown below.

for i in range(1, 101):  	if int(i*0.5)==i*0.5:  		print(i)
Qusनीचे दिखाए गए Python कोड के बराबर एक लिस्ट काम्प्रीहेन्शन लिखें।


A. [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
B. [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
C. [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
D. [i for i in range(1, 100) if int(i*0.5)=(i*0.5)]


Solution
B. [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]



Explanation
The code shown above prints the value ‘i’ only if it satisfies the condition: int(i*0.5) is equal to (i*0.5). Hence the required list comprehension is: [i for i in range(1, 101) if int(i*0.5)==(i*0.5)].
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad