✅ *Python Logic Building Interview Question* 🧠🐍
You have a list of numbers: nums = [3, 5, 7, 9, 12, 17, 20, 21]
*Question:*
Find and print all numbers in the list that are prime.
*Expected Output:* [3, 5, 7, 17]
*Python Code:* def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
prime_nums = [n for n in nums if is_prime(n)]
print(prime_nums)
*Explanation:*
– Checks each number with
is_prime() logic – Uses list comprehension for concise filtering
– Prints list of all prime numbers
💬 *Tap ❤️ for more logic-building questions!*
https://t.me/pythonadvisor


