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
Python Prime Number Checker Challenge
More Relevant Posts
-
Hello there and welcome to 'Learning Python with me'! Today I am going to show you how to create a text analyzer. As I am a little bit sick, I won't be doing a voiceover today, but I will explain step-by-step the workflow I used for this project: - Lists & .append(): I created an empty letters list and used the .append() method to save the three specific letters the user wants to search for. - The .count() method: I applied this directly to the text to easily calculate exactly how many times those saved letters appear. - .split() & len(): I used .split() to break the user's text into separate words, and len() to find out the total word count. - The print() function: Finally, I used print() along with f-strings to display the final analysis, formatting the output clearly so the user can easily read their results. Below you will find a video testing it with a simple phrase. Hope you enjoy it! #Python #PythonProject #Datascience #Sideproject #fyp #programming
To view or add a comment, sign in
-
👉 Your code doesn’t become smart… until it learns how to make decisions. 💡 That’s where conditional logic comes in. In Python, we use "if", "elif", and "else" to control what should happen next. age = 18 if age >= 18: print("You can vote") else: print("You cannot vote") Simple, right? But this is powerful. Because now your program is not just running… 👉 It’s thinking based on conditions You can add more situations: marks = 75 if marks >= 80: print("Grade A") elif marks >= 60: print("Grade B") else: print("Grade C") 💡 This is how programs: • Make decisions • Handle different situations • React to user input And honestly… We use conditional logic in real life every day: 👉 If it rains → take an umbrella 👉 If you’re tired → take rest 👉 Else → keep working 💡 That’s the real idea: Conditional logic = decision making Are you just writing code… or teaching it how to think? #Python #LearnPython #CodingBasics #ConditionalLogic #ProgrammingConcepts #Ifelse #CodingForBeginners #TechEducation #LearnWithMe
To view or add a comment, sign in
-
-
Hi guys, I know it’s delayed—now let’s dig into Python again for this post! 💭 Day 3 with Python… something finally clicked. The errors didn’t stop. The confusion didn’t magically disappear. But today… I wrote something that actually worked. Not just print("Hello, World!") Not just fixing errors… 👉 I made decisions in my code. Using if...else, my program could finally think (at least a little 😄) “IF this happens → do this” “ELSE → do something else” And suddenly, coding didn’t feel like typing… It felt like logic coming to life. 💡 That’s when I realized: Programming isn’t about memorizing syntax. It’s about teaching a machine how to think step by step. Every small concept—conditions, loops, functions— They’re not just topics… They’re building blocks of something bigger. Today it’s simple decisions. Tomorrow? Maybe something powerful. ✨ Step by step… line by line… growth is happening. #Python #CodingJourney #Day3 #LearnToCode #Programming #DeveloperLife #LogicBuilding #TechGrowth 🚀
To view or add a comment, sign in
-
Hello connections 👋 Welcome to Day 3 of my Python problem-solving series! Consistency is the key to growth, so here is today’s challenge 🚀 🧠 Day 3 Challenge: Find Factorial of a Number The factorial of a number n is the product of all positive integers less than or equal to n. 👉 Example: Input: 5 → Output: 120 (5 × 4 × 3 × 2 × 1 = 120) My Approach: Using Loop num = int(input("Enter a number: ")) fact = 1 if num < 0: print("Factorial does not exist for negative numbers") else: for i in range(1, num + 1): fact *= i print("Factorial =", fact) 📌 Explanation: We multiply all numbers from 1 to num. 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
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
-
-
🚀 Day 26 of My Python DSA Journey – Jump Game 🧠⚡ Today’s problem was a great example of how greedy thinking can simplify complex-looking problems. 📌 Problem You’re given an array where each element represents the maximum jump length from that position. 👉 Start at index 0 👉 Check if you can reach the last index 🔍 Approach I Used (Greedy) Instead of trying all possible jumps (which would be slow ❌), I tracked: ➡️ The farthest index I can reach at any point Steps: Initialize max_reach = 0 Traverse the array If current index > max_reach → ❌ cannot proceed Update: max_reach = max(max_reach, i + nums[i]) If max_reach reaches last index → ✅ done 💡 Key Learning ✔ Greedy approach avoids unnecessary computations ✔ Always track the maximum reachable position ✔ Early exit conditions make code efficient ✔ Not every problem needs DP or recursion ⏱ Complexity Time Complexity: O(n) Space Complexity: O(1) This problem taught me a big lesson: 👉 Sometimes the smartest solution is the simplest one. Consistency continues 🔥 #Python #DSA #GreedyAlgorithm
To view or add a comment, sign in
-
-
🚨 PYTHON LOGIC ALERT: Is the "Silent Killer" haunting your code? 🚨 Ever felt like your Python code was playing tricks on you? 🤨 You pass a list into a function, change it, and suddenly your original data is "sabotaged"—but your integers stay exactly the same? It’s not a glitch; it's the "silent killer" of Python logic: Mutability. We’ve just dropped a cinematic 3D "Code-Along" on our YouTube channel to help you master the laws of memory in the Floating Isles of Aetheria! 🛡️ What You’ll Discover in the Quest: Sir Integer (The Immutable Knight): He is stiff and rigid. If you try to "upgrade" his power, he doesn't just change, he "poofs" into dust and is replaced by a brand-new knight at a different memory address! The Royal Soup (The Mutable Cauldron): These are the shape-shifters of the realm. When you pass this soup through a Function Portal, you aren't sending a copy; you’re sending the location of the original pot. The Spicy Side-Effect: If a Chef inside the portal tosses in a "Magical Chili," your original soup back at the banquet table feels the heat instantly, even though the ID address never changed! 🎓 Level Up Your Logic Don't let your references haunt your debugging sessions. Watch the full lesson and grab the accompanying Progress Ritual Worksheet to master the Seal of Logic! 📺 Watch the Lesson Here: https://lnkd.in/dpVW5nrM 📚 Get the Worksheet: Access the full interactive guide on the Nazli Tech School TPT store via the link in our YouTube description! https://lnkd.in/dzeHfKM4 Stop guessing and start coding with alchemical precision. See you in Aetheria! 🧙♂️✨ #PythonProgramming #CodingLogic #PythonBeginner #NazliTechSchool #TechEducation #MutableVsImmutable #CodingTips
To view or add a comment, sign in
-
-
Day 9 of learning Python Today was all about diving deep into the "What if?" of programming. I spent the day exploring how to make my code more resilient and user-friendly by mastering Bugs and Exceptions in Python. 🐍💻 Here’s a breakdown of the key takeaways from my learning documentary today: 1. The Anatomy of a Mistake: Bugs vs. Exceptions Not all errors are created equal. I learned to distinguish between the two major categories: Bugs: These are the logic flaws. The program might run to the end, but it gives the wrong answer—like a calculator saying 2+2=5. Exceptions: These are the "show-stoppers." They happen during execution and will crash the program immediately if they aren't handled. 2. Identifying the Culprits I spent time matching specific error types to their causes. Recognizing these early is a superpower for any developer: SyntaxError: You missed a colon or a bracket. IndexError: You tried to access the 10th item in a list that only has 5. ValueError: You tried to turn the word "Apple" into an integer. NameError: You called a variable that hasn't been defined yet. 3. The Power of try/except The most exciting part of today was learning how to predict the unpredictable. Instead of letting a program crash when an error occurs, I can use a try/except block. The try block tests a piece of code. The except block provides a "safety net" to catch the error and keep the program running smoothly. 🛡️ The big lesson? A good developer doesn't just write code that works; they write code that knows what to do when things go wrong. Onwards to the next challenge! 📈 #Python #CodingJourney #SoftwareDevelopment #LearningToCode #TechSkills #ErrorHandling #PythonProgramming #Sololearn
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