A script executes. An application decides. #ZeroToFullStackAI Day 6/135: The Principle of Control Flow. For the past five days, our code has been a simple, top-to-bottom script. It executes one line after another, no matter what. The `ValueError` from our Day 5 challenge proved this is not enough. We need a way to handle different conditions. Today, we build the "brain" of our application. This is "Control Flow". It’s the mechanism that allows our code to analyze a situation and make a decision. Our tool for this is the `if/elif/else` structure: 1. 'if' : The primary gate. It asks a `True/False` question. 2. 'elif' : The secondary gate. It *only* asks its question if the `if` was `False`. 3. 'else': The "catch-all." It runs *only* if all preceding conditions were `False`. This is the first and most fundamental tool for writing non-linear, intelligent logic. We can now create different paths for our program to follow. We've taught our code to make logical decisions. But we still haven't built the "safety net" for when it receives bad data (like the `ValueError`). That is the final piece of our foundation. Tomorrow, we build the safety net: **Error Handling**. #Python #DataScience #SoftwareEngineering #AI #Developer #Logic
Learning Control Flow with if/elif/else in Python
More Relevant Posts
-
A script executes. An application decides. #ZeroToFullStackAI Day 6/135: The Principle of Control Flow. For the past five days, our code has been a simple, top-to-bottom script. It executes one line after another, no matter what. The ValueError from our Day 5 challenge proved this is not enough. We need a way to handle different conditions. Today, we build the "brain" of our application. This is Control Flow. It’s the mechanism that allows our code to analyze a situation and make a decision. Our tool for this is the if/elif/else structure: if: The primary gate. It asks a True/False question. elif: The secondary gate. It only asks its question if the if was False. else: The "catch-all." It runs only if all preceding conditions were False. This is the first and most fundamental tool for writing non-linear, intelligent logic. We can now create different paths for our program to follow. We've taught our code to make logical decisions. But we still haven't built the "safety net" for when it receives bad data (like the ValueError). That is the final piece of our foundation. Tomorrow, we build the safety net: Error Handling. #Python #DataScience #SoftwareEngineering #AI #Developer #Logic
To view or add a comment, sign in
-
-
The story of how we accidentally built a code refactoring tool. It started with a simple question: “Why is our code so messy?” Six months later, that question turned into Refactron v0.1.0 — an AI-powered tool that does what every developer secretly wishes they could do: clean up code automatically. We tried it on our own codebase first. The results were… eye-opening. Turns out we had more technical debt than some small countries have actual debt. But here’s the thing — it works. ✅ 98 tests passing. ✅ 90% coverage. And code that’s actually cleaner and more readable. Now it’s live on PyPI for everyone to try (and judge our code quality 😅). $ pip install refactron Docs: https://lnkd.in/dmdtpBCC Website: https://refactron.us.kg/ P.S: If you find any bugs, they’re probably features we haven’t documented yet. #Python #CodeRefactoring #AI #DeveloperTools #OpenSource
To view or add a comment, sign in
-
-
Project Overview – “Optimized Truck Loading and Routing” For my Design & Analysis of Algorithms course, I built a self‑contained Python program that tackles a real‑world logistics challenge: selecting the most valuable set of packages for a single truck and then finding the shortest delivery route for those packages. The core of the work is split into two classic algorithmic problems: 1. 0/1 Knapsack (DP) – I implemented a dynamic‑programming solution that maximizes total value while respecting the truck’s weight capacity. The algorithm runs in O(n · W) time, where n is the number of packages and W the capacity. 2. Route optimization – After the packages are chosen, the program builds a graph of delivery locations. It uses Dijkstra for exact shortest‑path queries and an A* implementation (with Euclidean heuristic) when node coordinates are available. For the traveling‑salesperson problem on the selected destinations, I provided both a fast nearest‑neighbor heuristic and an exact Held‑Karp DP (feasible for up to ~20 stops). Research angle The project was also a small research exercise: I wanted to see how well a simple DP knapsack would perform when combined with graph‑search routing, and whether the added heuristic of A* noticeably reduced runtime on sparse road networks. The results showed that for modest problem sizes (≤ 30 packages, ≤ 15 destinations) the combined approach runs in well under a second, and the A* heuristic cuts the number of expanded nodes by roughly 30 % compared with Dijkstra alone. Outcome The final script, `truck_knapsack_routing.py`, includes a sample dataset, a command‑line demo, and basic unit tests. It demonstrates a complete pipeline: package selection → shortest‑path matrix → TSP route → printable delivery plan. The code is modular, heavily commented, and can be extended to larger fleets, time windows, or vehicle‑capacity constraints for future work. Open source code GitHub Kuda1721 #Algorithm #AI #ML #python
To view or add a comment, sign in
-
The code is perfect. The user is not. #ZeroToFullStackAI Day 5/135: The Challenge Solution & The Next Prerequisite. Outstanding work on the Day 4 calculator challenge. I am sure many of you had written the correct, functional solution. The attached code is the 100% correct answer for the tools we've established (Days 1-3). It correctly uses `int()` and `float()` to perform explicit type casting and calculate the revenue. This demonstrates mastery of our primitives. But now, we introduce a new variable into our system: the unpredictable user. What happens if a user types "apple" instead of "50"? Our code works perfectly: the `int()` function, doing its job as a feature, raises a `ValueError` to tell us "this is not a valid integer." Remember 'Value Error' is not an error but a feature to make the system robust. This is not a "flaw." It's an *unhandled event*. Our current tools allow us to execute statements. They don't allow us to make *decisions* or *handle exceptions*. We have no "safety net" because we haven't built one yet. This `ValueError` is the logical prerequisite for our next lesson. To handle it, we need a new class of tools. Tomorrow, we forge the first one: **Control Flow (`if/else`)**. #Python #DataScience #SoftwareEngineering #AI #Developer #Architecture
To view or add a comment, sign in
-
-
Data cleaning used to be my biggest time sink. Dozens of files, hundreds of thousands of rows, duplicates, missing fields, wrong encodings… you name it! So I decided to built my own solution. Using my new best friends, Python and pandas, I wrote a script that automates the full process: 👉 Reads multiple CSVs at once 👉 Removes duplicates by key columns 👉 Normalises column names and encodings 👉 Outputs clean, ready-to-use files per client, instantly Something that once took hours of manual work now runs in seconds. The best part? It scales. Whether it’s 10K or 2M rows, I can prepare datasets for clients in minutes! Consistent, validated, and ready for delivery. I’ve learned that automation isn’t just about saving time. It’s about building systems that work for you, so you can focus on strategy instead of repetition. What’s the one data task you’d automate first if you could? 👇 #Python #Pandas #DataScience #Automation #DataCleaning #Productivity #DataEngineering #LeadGeneration #B2CData #VIPResponse
To view or add a comment, sign in
-
-
🧩 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐖𝐞𝐞𝐤𝐥𝐲 𝐂𝐨𝐧𝐭𝐞𝐬𝐭 𝟒𝟕𝟒 🚀 Just wrapped up this week’s 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗪𝗲𝗲𝗸𝗹𝘆 𝗖𝗼𝗻𝘁𝗲𝘀𝘁 𝟰𝟳𝟰 — managed to 𝘀𝗼𝗹𝘃𝗲 𝟮 𝗼𝘂𝘁 𝗼𝗳 𝟰 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 🎯 Each problem brought a new challenge in logic building and optimization — and it was a great brain workout 🔹 𝗤𝟭. 𝗙𝗶𝗻𝗱 𝗠𝗶𝘀𝘀𝗶𝗻𝗴 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: • Created a hash map to track all numbers present in the array. • Found the min and max elements to define the expected range. • Identified numbers missing from that range efficiently. ⏱️ 𝗧𝗶𝗺𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n + (max − min)) 💾 𝗦𝗽𝗮𝗰𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n) — for the hash map ➡️ Key takeaway: Simple hashing + range logic can replace sorting-based approaches. 🔹 𝗤𝟮. 𝗠𝗮𝘅𝗶𝗺𝘂𝗺 𝗣𝗿𝗼𝗱𝘂𝗰𝘁 𝗼𝗳 𝗧𝗵𝗿𝗲𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗔𝗳𝘁𝗲𝗿 𝗢𝗻𝗲 𝗥𝗲𝗽𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: • Observed that the product’s magnitude depends on the largest absolute values. • Since one number can be replaced in [-10⁵, 10⁵], tested both extremes (10⁵ and −10⁵). • Chose the maximum product possible between the two cases. ⏱️ 𝗧𝗶𝗺𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n) 💾 𝗦𝗽𝗮𝗰𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(1) — constant space ➡️ Key takeaway: Sometimes, focusing on mathematical relationships beats complex iteration logic. 💭 𝗥𝗲𝗳𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀 • Solved 2 problems confidently ✅ • Improved speed in analyzing mathematical patterns and handling edge cases • Next goal → solve 3/4 questions and focus more on binary search & greedy optimization #LeetCode #WeeklyContest474 #ProblemSolving #Python #CompetitiveProgramming #DSA #CodingJourney #ContinuousLearning #Algorithms
To view or add a comment, sign in
-
-
Day 50: Binary Search Tree Iterator (BST) 🌲 I'VE HIT THE HALFWAY MARK! Day 50 of #100DaysOfCode is dedicated to mastering the "Binary Search Tree Iterator." This challenge requires designing a class that enables in-order traversal of a BST using constant time complexity for the key operations. The key insight is using an Iterative Inorder Traversal with a Stack: __init__ (Initialization): The constructor doesn't traverse the whole tree. It uses a helper function (_push_left) to initially push the root and all its left descendants onto the stack. This positions the stack to start at the smallest element. next(): This method retrieves the next smallest element. It simply pops the top element from the stack, and then immediately checks if that popped node has a right child. If it does, it calls _push_left on the right child to load the next set of smallest elements onto the stack. Efficiency: The design ensures that while an element is pushed and popped exactly once overall (O(n) total time), the amortized time complexity for both next() and hasNext() is O(1). This was a perfect problem to mark the halfway point—combining Data Structures and Algorithmic Design! #Python #DSA #Algorithms #BST #Iterator #Stack #100DaysOfCode
To view or add a comment, sign in
-
-
Excited to share that PromptLint is now live on PyPI! After weeks of building and refining, I've just published PromptLint - a CLI tool designed to help developers write better prompts. It analyzes prompts across three critical dimensions: clarity, cost efficiency, and security. The tool does something you haven't seen elsewhere - it combines heuristic-based analysis with real token counting to give you actionable feedback. You get clarity scores based on prompt structure and language precision, cost estimates across 7 major LLM models (GPT-4o, Claude 3.5 Sonnet, and others), and security scanning that detects common prompt injection patterns. The CLI is simple - just point it at your prompt file and get structured analysis in console, JSON, or Markdown format. There's also a diff command that shows how prompt changes impact your scores and costs across models. You can grab it now with a simple: `pip install promptlint` The full source is on GitHub at `https://lnkd.in/duskFCbm Check out the screenshots below to see it in action. #PromptEngineering #LLM #Python #OpenAI #Claude #DevTools #PyPI #CLI #SecurityTesting #CostOptimization #AI #SoftwareDevelopment #OpenSource #GitHubProjects #DeveloperTools #PromptOptimization #TokenCounting #TechTools
To view or add a comment, sign in
-
-
Most engineers have used an MCP server. Few have built one. In this new post, Pablo Tomas Fernandez walks through creating a fully working MCP server that connects directly to Semaphore’s API. It takes under 50 lines of Python to make your CI/CD setup conversational — list projects, pull build data, even ask why a build failed. A short, hands-on look at what AI + CI/CD actually feels like. Read the full post → https://lnkd.in/dCtjmgDX
To view or add a comment, sign in
-
More from this author
-
The Rising Threat of AI-Led Cyber Attacks in Transportation Systems
Sumit Kumar 1mo -
Navigating the AI Wave: Prudence for Retail Investors Amidst IMF's "Echoes of Dot-Com" Warning
Sumit Kumar 6mo -
Navigating the Rupee Plunge: Empowering Indian Students to Overcome Global Financial Challenges
Sumit Kumar 1y
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