Hello connections 👋 Welcome to Day 6 of my Python problem-solving series! Consistency and practice make coding easier every day 🚀 🧠 Day 6 Challenge: Check if a Number is Prime Write a Python program to check whether a given number is prime or not. 👉 Example: Input: 7 → Output: Prime Input: 9 → Output: Not Prime My Approach 1: Basic Method (Factor Count) num = int(input("Enter a number: ")) c= 0 if num <= 1: print("Not Prime") else: for i in range(1, num + 1): if num % i == 0: c += 1 if c == 2: print("Prime") else: print("Not Prime") 📌 Explanation: A prime number has exactly 2 factors: 1 and itself. My Approach 2: Optimized Method (Using √n) num = int(input("Enter a number: ")) if num <= 1: print("Not Prime") else: for i in range(2, int(num**0.5) + 1): if num % i == 0: print("Not Prime") break else: print("Prime") 📌 Explanation: We only check divisibility up to √n, making it faster for large numbers. Now it’s your turn 👇 Try solving it with your own logic or suggest a better approach in the comments. Let’s learn and grow together 🚀 #Python #CodingChallenge #ProblemSolving #Programming #30DaysOfCode
Check if a Number is Prime in Python
More Relevant Posts
-
A smarter way to think about Python: it's not just about writing code; it's about solving problems effectively. Many beginners jump straight into complex scripts without understanding the foundational logic and syntax. This approach often leads to frustration and doubt. Start with the basics. Familiarize yourself with simple concepts like variables, loops, and functions. These building blocks will help you develop a strong understanding of how Python works. Remember: mastering the fundamentals is key to overcoming common coding hurdles. A typical mistake is treating coding as a linear task. Instead, think iteratively. Programming is about refining your thoughts and solutions. Write a piece of code, test it, identify errors, and improve it. It's a cycle that helps solidify your learning. Every coder faces challenges, but overcoming them is part of the journey. The beauty of Python lies in its simplicity and versatility. With hands-on practice and a structured approach, you’ll transform from a novice to a competent coder in no time. Want the full walkthrough in class? Details: https://lnkd.in/g-FM66wq #Python #LearnToCode #CodingForBeginners #TechSkills
To view or add a comment, sign in
-
🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
To view or add a comment, sign in
-
-
🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
To view or add a comment, sign in
-
-
🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
To view or add a comment, sign in
-
-
🚀 I’m currently strengthening my skills in Python development, focusing on building a solid foundation in logic and clean coding practices 🐍 As part of this process, I’ve been working on: 🔹 Designing functions to solve specific problems in a structured way 🔹 Using lambda functions to simplify simple operations and write more concise code 🔹 Implementing logic to analyze and validate strings, such as detecting palindromes One of the most interesting exercises was building a function that checks whether a word is a palindrome by comparing characters from both ends toward the center: def is_palindrome(text): left = 0 right = len(text) - 1 while right >= left: if not (text[left].lower() == text[right].lower()): return False left += 1 right -= 1 return True print(is_palindrome("Racecar")) # True This type of exercise has helped me strengthen key skills such as: ✔️ Logical thinking ✔️ Index handling and control flow ✔️ Writing clean and efficient code I’ve also been applying lambda functions for simple operations in a more concise way: square = lambda x: x ** 2 print(square(2)) # 4 Understanding lambda functions has been a bit challenging, especially when deciding when to use them versus traditional functions. I’m still working on building that intuition. If you have experience with lambda functions, I’d really appreciate your insights #Python #SoftwareDevelopment #Programming #Code #ContinuousLearning
To view or add a comment, sign in
-
-
Teach With Tech: Understanding range() in Python 🧠💡 Let’s explore a simple yet powerful concept every Python beginner should know — range(). If you’ve ever wondered how programmers make things repeat without writing the same code over and over, this is one of the go-to tools. 🔹 What is range()? range() is a built-in Python function that generates a sequence of numbers. Think of it as a smart counter that does the counting for you. 🔹 Basic Syntax range(start, stop, step) start → where counting begins stop → where it ends (this number is NOT included) step → how much it increases each time 🔹 Simple Examples ✅ Example 1: for i in range(5): print(i) Output: 0 1 2 3 4 👉 Starts from 0 by default and stops before 5. ✅ Example 2: for i in range(2, 7): print(i) Output: 2 3 4 5 6 👉 Starts from 2 and stops before 7. ✅ Example 3: for i in range(1, 10, 2): print(i) Output: 1 3 5 7 9 👉 Counts with a step of 2. 🔹 Why it matters range() helps you: - Automate repetition - Keep code clean and concise - Control loops with ease 🔹 Beginner Tip If your loop seems to “miss” the last number you expected… don’t worry 😄 👉 range() always stops BEFORE the final number. Learning small concepts like this may seem simple, but they’re the building blocks of real-world programming. Keep learning. Keep creating. 🚀 @TechCrush.pro #RisewithTechCrush #Tech4Africans #LearningwithTechCrush
To view or add a comment, sign in
-
-
Hello connections 👋 Welcome to Day 2 of my Python problem-solving series! 🧠 Day 2 Challenge: Check if a number is Prime A prime number is a number greater than 1 that has only two factors: 1 and itself. 👉 Example: Input: 7 → Output: Prime Input: 9 → Output: Not Prime My Approach 1: Basic (Factor Counting Method) num = int(input("Enter a number: ")) c = 0 if num <= 1: print("Not prime") else: for i in range(1, num + 1): if num % i == 0: c += 1 if c == 2: print("Prime") else: print("Not prime") 📌 Explanation: Here, we count how many numbers divide num. If the count is exactly 2 → it’s a prime number. ⚡ My Approach 2: Optimized num = int(input("Enter a number: ")) if num <= 1: print("Not prime") else: for i in range(2, int(num**0.5) + 1): if num % i == 0: print("Not prime") break else: print("Prime") 📌 Explanation: Instead of checking all numbers, we only check up to √n, which makes the solution much faster for large inputs. Now it’s your turn 👇 Try solving it using your own approach or suggest improvements! Let’s learn and grow together 🚀 #Python #CodingChallenge #ProblemSolving #30DaysOfCode #Programming
To view or add a comment, sign in
-
#7 Days of Advanced Python — Learning Beyond Basics I’ve been working with Python for quite some time now — building projects, solving problems, and exploring different concepts. But recently, I realized something. Knowing Python is one thing. Using Python efficiently in real-world workflows is something else. There are so many small things that we often ignore — tools, setup, debugging, project structure — but those are exactly the things that make a big difference when you start building seriously. So I decided to start a small 7-day challenge for myself. Every day, I’ll share one thing I’m learning that is helping me move from just “writing code” to actually “building better systems”. Not theory. Just practical improvements. #𝗗𝗮𝘆 𝟭 — 𝗨𝗽𝗴𝗿𝗮𝗱𝗶𝗻𝗴 𝗺𝘆 𝗣𝘆𝘁𝗵𝗼𝗻 𝘄𝗼𝗿𝗸𝗳𝗹𝗼𝘄 Today I explored a tool called 𝘂𝘃 — 𝗮 𝗺𝗼𝗱𝗲𝗿𝗻 𝗣𝘆𝘁𝗵𝗼𝗻 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 𝗺𝗮𝗻𝗮𝗴𝗲𝗿. Until now, I was mostly using pip with virtual environments. It worked, but it often felt a bit fragmented — multiple steps, dependency issues, and sometimes inconsistent setups. Using 𝘂𝘃 felt different. It’s not just about installing packages faster, it’s about simplifying the entire workflow. What stood out to me: • Faster dependency installation • Lockfiles for reproducible environments • Simpler project setup • Cleaner and more predictable workflow What I liked most is how it removes small frictions that we usually ignore — like broken environments or “it works on my machine” problems. This made me realize something important: Improvement in development is not always about learning new concepts. Sometimes, it’s about upgrading the way you work. If you want to explore it, the official documentation is a great place to start: https://docs.astral.sh/uv/ Curious — are you still using pip for everything, or have you explored tools like uv? #Python #AdvancedPython #LearningInPublic #DevTools #SoftwareDevelopment
To view or add a comment, sign in
-
-
🎯 Struggling to get better at Python? Here’s the reality most beginners face 👇 ❌ Watching tutorials non-stop ❌ Copying code without thinking ❌ Getting stuck on small errors ❌ Giving up too early 💡 The shift that changes everything: Python isn’t about remembering syntax… It’s about building logic. ✅ Try this instead: 🔹 Code along, don’t just watch 🔹 Break problems into small steps 🔹 Debug your own errors (this is where learning happens) 🔹 Build tiny projects (even simple ones count!) 🚀 Focus areas that actually matter: ✔ Variables & Data Types ✔ Conditions & Loops ✔ Functions ✔ Data Structures (Lists, Dicts, Sets) ✔ Error Handling ✔ Working with Files 🔥 Golden Rule: Consistency beats intensity. 30 minutes daily > 5 hours once a week. 📌 If you're stuck, you're not failing — you're learning. Keep going. It clicks. 💡 #Python #LearnToCode #CodingJourney #Programming #Developers #TechSkills #100DaysOfCode
To view or add a comment, sign in
-
-
One thing that immediately stands out in Python is indentation — it’s not just for readability, it’s part of the syntax. Unlike many languages that use {} to define blocks, Python uses indentation to structure code. A few key takeaways: → Indentation defines code blocks (loops, functions, conditionals) → Consistency matters — even a small mismatch can break your code → It forces clean and readable code by design → Common practice is using 4 spaces per indentation level Example: if True: print("This works") if True: print("This will throw an error") What I like most is how Python encourages writing clean, organized code from the start. It’s a small concept, but it builds strong coding discipline. #Python #Programming #CleanCode #Developers #Learning
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development