Day 26 of My Python Full-Stack Journey — Finding the Nth Prime Number 🔢 Today I tackled a classic algorithmic challenge: writing a program to find the Nth prime number. It sounds simple, but it pushed me to think about efficiency — the difference between a brute-force check and an optimized approach using early termination and square root logic is huge when N gets large. Key concepts I reinforced today: → What makes a number prime (divisible only by 1 and itself) → Looping and counting logic in Python → Optimizing trial division using math.sqrt() → Writing clean, readable functions A simple is_prime() helper + a counter loop gets you there, but understanding why you only check up to √n is where real problem-solving kicks in. Snippet from today: python import math def is_prime(n): if n < 2: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def nth_prime(n): count, num = 0, 1 while count < n: num += 1 if is_prime(num): count += 1 return num print(nth_prime(10)) # Output: 29 Every small program like this is building the logical foundation I'll need for the full-stack projects ahead. 💪 26 days in — consistency is the real algorithm. 🔥 #Python #100DaysOfCode #FullStackDevelopment #CodingJourney #Day26 #Programming #LearnToCode #PythonProgramming
Finding the Nth Prime Number with Python
More Relevant Posts
-
🔍 Day 36 of My Problem Solving Journey Today I explored one of the most important concepts in strings — Searching & Finding. In Python, we often use methods like: ✔️ find() → to get the index of a substring ✔️ in → to check existence ✔️ index() → similar to find but throws error if not found But instead of just using built-in functions, I tried to understand the internal logic behind searching 👇 Find the position of a substring without using built-in functions. 🧠 My Approach: Traverse the string Compare characters one by one Return index if match is found Return -1 if not found def my_find(s, sub): for i in r print(my_find("manuuuu", "u")) # Output: 3 ✨ What I learned: How searching works internally Difference between find() and index() Importance of logic building instead of relying on built-ins 📈 Small steps every day = Big growth over time! #Day36 #Python #CodingJourney #ProblemSolving #100DaysOfCode #Learning #Developers #Programming Rudra Sravan kumar
To view or add a comment, sign in
-
-
I wanted to build a small Python project that was both logical and fun. So I created a 5-second math challenge game**. 🎮 The idea is simple but tricky: 1️⃣ You enter a number between 1 and 10 2️⃣ Python generates all pairs whose sum equals that number 3️⃣ The system secretly chooses one pair + a random operation 4️⃣ You must guess the result before the 5-second timer ends To make it harder: The game shows 4 options Only one is correct The other three are trap answers generated from other pairs and operations. Every round is random, so you can’t memorize the answers. 🛠 Tech used: Python + Gradio + Google Colab Small project, but a fun way to practice: • algorithmic thinking • randomness • building simple UI with Python Check out the video below 👇 Would you play this game? 😄 #Python #CodingProject #Gradio #PythonDeveloper #BuildInPublic
To view or add a comment, sign in
-
Most beginners don’t struggle with Python… they struggle with thinking like Python simple shift that changed everything for me.... 💡 When should you use a for loop vs a while loop? Use a for loop when you already have a sequence (Lists, strings, numbers via range()) Use a while loop when you’re waiting for a condition to change (True → False) 📊 Range() = Your loop’s control panel It has 3 simple parts: Start → where to begin Stop → where to end (not included ❗) Step → how much to jump Example: for i in range(1, 10, 2): print(i) 🧠 Core concepts you must understand: ✔️ Boolean → Only 2 states: True or False ✔️ Concatenate → Join things together (like text) ✔️ Escape characters → Control special behavior (\n, \") Why this matters? Because this is where you stop writing “random code”… and start writing logical, structured programs Most people skip these basics… and then struggle later with real projects. I’m focusing on mastering the fundamentals first. #Python #Coding #Programming #DataAnalytics #LearnPython #100DaysOfCode #TechSkills #Automation #AI
To view or add a comment, sign in
-
-
For my Day 15 I covered Python String Formatting and I have to say — this one clicked really fast for me. Here is what I covered: F-Strings This is the modern way to format strings in Python (available from version 3.6). All you do is put the letter f in front of your string and use curly brackets {} to drop in your variables directly. It is clean, simple, and easy to read. I actually enjoyed writing these. .format() Method This is the older way of doing the same thing. Instead of putting f at the front, you write your string normally and call .format() at the end to pass in the values. Still works perfectly and good to know, but f-strings feel much neater. Placeholders and Modifiers This was my favourite part. Inside the curly brackets {}, you can add a colon : followed by a modifier to control exactly how your value is displayed. For example: :.2f gives you 2 decimal places :, adds a comma as a thousand separator :% converts a number to a percentage :> :< :^ lets you align your text right, left, or centre So instead of just printing a raw number like 1500000, I can now print it as $1,500,000.00. That small difference makes everything look so much more professional. As someone learning Python for data analysis, I can already see how useful this will be when I start working with real data and building reports in pandas. Day 16 we go into revision mode 5 days of practicing everything I have covered so far before jumping into pandas. The foundation is almost ready. #Python #100DaysOfCode #DataAnalysis #LearningInPublic #W3Schools #NeverStopLearning
To view or add a comment, sign in
-
-
A few weeks ago, I started learning Python, committing to just 3% progress daily. I covered the basics (lists, tuples, sets, loops, conditionals, operators) and at some point, I felt like I was getting the hang of it. Then a friend challenged me with a simple logical problem… and that moment really humbled me. It made me realize something important: knowing syntax isn’t the same as knowing how to think with code. Python (and programming in general) is less about memorizing concepts and more about how well you can apply logic. How you break problems down, manipulate variables, structure conditions, and connect different pieces to get the result you want. I took that advice seriously, paused rushing through topics, and focused on strengthening my problem-solving and logical thinking. The improvement has been very noticeable. Takeaway: Don’t just rush through the basics. Spend time building your logic. Once your thinking improves, everything else becomes easier, and you’ll already be ahead of many who only focus on syntax. #Python #LearnToCode #DataAnalyst #PythonBeginner #TechSkills #ProblemSolving #Logic #DataAnalysis #web3 #100DaysOfCode #TechGrowth #SelfImprovement #ContinuousLearning #Biuldinpublic
To view or add a comment, sign in
-
-
🧠 Python Concept: for-else Loop Yes… Python loops can have an else block 👀 🤔 How It Works The else runs only if the loop completes normally (not if it breaks). 🧪 Example numbers = [1, 3, 5, 7] for num in numbers: if num % 2 == 0: print("Even found") break else: print("No even numbers") ✅ Output No even numbers ⚡ When break Happens numbers = [1, 3, 4, 7] for num in numbers: if num % 2 == 0: print("Even found") break else: print("No even numbers") ✅ Output Even found 🧒 Simple Explanation Imagine a teacher checking students 👩🏫 If she finds a rule-breaker → stops (no else) If she checks everyone → says “All good!” (else runs) 💡 Why This Matters ✔ Cleaner search logic ✔ Avoids extra flags ✔ Pythonic pattern ✔ Useful in real projects 🐍 Python loops can have an else block 🐍 It runs only when the loop completes without a break. 🐍 A small feature, but very powerful. #Python #PythonTips #PythonTricks #AdvancedPython #Loop #ForElse #PythonLoop #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
Day 15/100: My code finally talked back! 🎙️✨ For two weeks, I’ve been talking at my computer. Today, it started listening. I mastered the input() function! The Catch: Python is a bit of a literalist. If you tell it you’re 25, it thinks you’re the word "25," not the number. Without Type Casting (int()), your math becomes a mess. It's the difference between "25 + 1 = 26" and "25 + 1 = 251." 🤦♂️ The Code: Python name = input("Enter your name: ") age = int(input("Enter your age: ")) # Casting to int so Python doesn't get confused print(f"Hi {name}! {age} is a great age to master Python. 🚀") Moving from static scripts to interactive tools feels like a massive level-up. ⬆️ #100DaysOfCode #Python #InteractiveCode #CodingLife #LearnToCode
To view or add a comment, sign in
-
-
Day 27 of My Python Full-Stack Journey 🐍 Today's challenge: Reverse the words in a sentence — without using .reverse() or .join() Sounds simple? It made me think differently about strings and loops. Here's the logic I built from scratch: python def reverse_words(sentence): words = [] word = "" for char in sentence: if char == " ": if word: words.append(word) word = "" else: word += char if word: words.append(word) # Rebuild sentence manually result = "" for i in range(len(words) - 1, -1, -1): result += words[i] if i != 0: result += " " return result print(reverse_words("Hello World from Python")) # Output: Python from World Hello Key takeaways from today: → Manual string parsing builds real intuition → Constraints force creativity — no shortcuts = deeper understanding → Every loop you write by hand teaches you what built-ins do under the hood 27 days in. Still going strong. 💪 What would YOU add to make this more efficient? #Python #100DaysOfCode #FullStack #PythonProgramming #CodingJourney #LearningInPublic #Day27
To view or add a comment, sign in
-
-
Python Clarity Series – Episode 19 Topic: map() vs Loop 📌 Two ways to apply a function to a list. Traditional loop: nums = [1,2,3,4] squares = [] for i in nums: squares.append(i*i) Pythonic way: nums = [1,2,3,4] squares = list(map(lambda x: x*x, nums)) 👉 map() applies a function to every element. Result: [1, 4, 9, 16] 💡 Clarity Thought: Loop → easy to understand map() → shorter and functional style Both are correct. Python gives multiple ways to solve problems. Understanding both improves coding flexibility. #PythonLearning #CodingEfficiency #FutureDevelopers
To view or add a comment, sign in
-
-
🧠 Python Concept: List Comprehension Write loops in one clean line 😎 ❌ Traditional Way numbers = [1, 2, 3, 4, 5] squares = [] for num in numbers: squares.append(num * num) print(squares) ✅ Pythonic Way numbers = [1, 2, 3, 4, 5] squares = [num * num for num in numbers] print(squares) 🧒 Simple Explanation Think of it like a shortcut formula 🧮 ➡️ Take each item ➡️ Apply logic ➡️ Store result — all in one line 💡 Why This Matters ✔ Less code, more clarity ✔ Faster to write ✔ Easy to read once you learn it ✔ Widely used in real projects ⚡ Bonus Example (With Condition) even_squares = [num * num for num in numbers if num % 2 == 0] print(even_squares) 🐍 Python is all about writing clean and expressive code 🐍 Master list comprehension = level up 🚀 #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
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