Python Logic Building Interview Question* 🧠🐍 You have a list of…

***

✅ *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
Telegram
AI • CodeLab
Learn Python with Scratch 🤠 Free Coding Notes🥳 Free Source Code📑 INSTAGRAM CHANNEL https://www.instagram.com/aicodelab_?igsh=MWdrd2h5bjh5cm5ocQ== WHATSAPP CHANNEL https://whatsapp.com/channel/0029Vb6r6218kyyQgBDNjm26
❤10👍1
November 8, 2025 5.5K 5