Day 11/60 Continuing Chapter 2- Flow Control Topic II - Coding Else Statements Great software doesn’t just decide what to do when a condition is True , it also has a back-up plan if the condition is False . For example - making a program that switches the lights on if is_on is True and off if is_on is False . We already know if statements help us execute code if a condition like available is True . 🧩Code available = True if available: print("In stock") 🖥️Output In stock Let's add another if statement that uses the not operator to run a different code block if the condition is False . 🧩Code available = True if available: print ("In stock") if not available print ("Out of stock") 🖥️ Output In stock Now Instead of creating two if statements, we use an if / else statement to achieve the same result. 🧩Code available = False if available: print("1 in stock") else: print("Out of stock") 🖥️ Output Out of stock The else statement of an if / else statement always goes at the end. 🧠Challenge of the day What does this display in the console? 🧩Code is_subscribed = True if is_subscribed: print("Enjoy 10% off!") else: print ("Become a subscriber!") #python #programming #ai #bigtech
Flow Control with Else Statements in Python
More Relevant Posts
-
Day 10/60 Continuing Chapter 2: Flow Control Continuing Topic l - Making Decisions 2. Code blocks if statements don't decide on skipping or running the entire code. They only make decisions about a code block. We use an indentation of two spaces to highlight code blocks, like indenting this display statement. Indentation refers to the space between the code and the code editor's margin. A code block can be more than a one-liner. All lines with the same indentation belong to the same code block. We can see it here when we use print() to add one more line at the beginning. 🧩Code if True: print ("Look at me!") print("I'm a code block") 🖥️Output Look at me! I'm a code block If the indentation is incorrect, the computer can't understand your code. This leads to an IndentationError showing up in the console. Instead of using the boolean True , we can save it in a variable like greet and use it as the condition. 🧩Code greet = True if greet: print("Hello!") 🖥️Output Hello! Using a variable like greet set to False allows us to skip code like the display statement. 🧩Code greet = False if greet: print("Hello!") 🖥️Output is empty 🧠Challenge of the day What is the output of this code? 🧩Code if True: print ("Look at me!") print("I'm a code block") #python #ai #programming #bigtech
To view or add a comment, sign in
-
The goal was simple: take a cluttered directory and transform it into a structured, searchable archive in seconds. Key Features: Sequential Numbering: Automatically renames files based on a custom prefix (e.g., Project_Alpha_001). Extension Filtering: Targets specific file types while leaving others untouched. Error Handling: Prevents accidental overwrites and handles edge cases with duplicate names. 🛠️ The Tech Stack Language: Python Library: os (for navigating the file system and executing renames) 💡 Why Automation Matters It’s not just about saving five minutes today; it’s about building systems that scale. Automating these "micro-tasks" frees up mental bandwidth for the complex problem-solving that actually moves the needle. Check out the snippet below to see how a few lines of code can reclaim your afternoon! #Python #Automation #Coding #Productivity #SoftwareDevelopment #WorkflowOptimization #PythonProgramming Kodbud
To view or add a comment, sign in
-
AI-driven inspection significantly reduces human error and downtime, providing 100% traceability that traditional manual checks simply cannot match. I have open-sourced my latest project: a hybrid YOLO and Mathematical-based vision tool designed to run on standard IP cameras and Python 3.10. Explore the framework here: 👉 https://lnkd.in/dCU_kJbc #IndustrialAutomation #ComputerVision #YOLOv8 #Industry40 #Python #SmartManufacturing #Instrumentation #OpenSource
To view or add a comment, sign in
-
“I know how to code… until OOP walks in and humbles you.” 😄 That’s exactly what happened when I started learning Encapsulation. Initially, I thought: 👉 “Encapsulation = making variables private to prevent misuse.” But it’s much deeper. --- 💡 What changed Earlier: user.balance += 500 Now: user.deposit(500) 👉 Same result, but better design. Encapsulation is about: - Controlling access - Enforcing business rules - Designing clear interfaces --- 🔍 Game changer: "@property" @property def total_price(self): return sum(item.price for item in self.items) 👉 Looks like data, but runs logic 👉 Can evolve (tax, discounts) without breaking APIs --- 🧠 Key insight Encapsulation enables: - Low coupling - High cohesion - Safe refactoring It’s not about restricting access, it’s about: «Guiding correct usage through design» --- 🔥 Takeaway I thought I knew coding. Turns out, I was just writing instructions… not designing systems. Still learning, still improving 🚀 #SoftwareEngineering #Python #OOP #Encapsulation #BackendDevelopment #SystemDesign #CleanCode #Programming #Developers #Tech #LearningInPublic
To view or add a comment, sign in
-
🚨 Most developers process data using loops (slow way) I was using loops everywhere (wrong way) I thought it’s simple and easy to control But when my data started growing… everything became slow 🐢 Execution time increased Code became messy Debugging was painful Then I started using Pandas That’s when things changed ⚡ 👉 Loops process data row by row (slow) 👉 Pandas uses vectorization (fast) 🚀 👉 Built-in functions reduce code and errors Example: Loop way ⛔ You iterate each row manually Pandas way ✅ Data is processed in bulk Result: Less code + faster execution + clean logic Lesson: If you are working with data, don’t rely on loops everywhere. Use Pandas smartly. It will save time and improve performance. Have you ever faced slow performance because of loops? 🤔 #Python #Pandas #DataScience #MachineLearning #Coding #Programming #Developers #TechLearning #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 2 of My AI Learning Journey Today was all about setting up a strong development environment — building the foundation for everything ahead. Here’s what I covered: ✅ Installed VS Code with a fresh setup ✅ Explored important VS Code options for future coding ✅ Installed Git & Git Bash on Windows ✅ Set up Miniconda for Python & AI environments ✅ Learned Git Bash + Miniconda + VS Code integration (step by step) ✅ Troubleshooting common issues in Miniconda & Git Bash integration This day really helped me understand how important a clean and well-configured environment is before starting actual development. Now I feel more confident to move forward into practical coding and AI projects 💻 📌 Consistency is the key — one step every day. #AI #LearningJourney #Python #VSCode #Git #Miniconda #Programming #StudentLife #smartiteyes #iteyes
To view or add a comment, sign in
-
Python Journey — Day 21 | OOPs with Real-Time Applications Today I continued practicing Object-Oriented Programming (OOPs) by building real-time class-based programs. Problems I solved : 💡 Car Class Simulation: • Created a Car class with attributes like name, engine, color, price, mileage • Implemented methods for displaying details • Designed accelerate() and brake() functionalities • Simulated real-time behavior like speed increase and brake control 💡 Arithmetic Operations System: • Built a class to perform arithmetic operations • Implemented addition, subtraction, division, multiplication, remainder, and power • Designed a menu-driven program for user interaction • Allowed dynamic selection of operations I implemented these using classes, objects, methods, and user interaction logic to understand real-world application of OOP concepts. Today felt exciting as I applied OOP concepts to real-world scenarios instead of simple problems. #Python #PythonDeveloper #Programming #Coding #LearningJourney #OOP #ProblemSolving #CodeEveryDay #FutureDeveloper #KeepLearning #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
Back to Basics: Mastering the Bubble Sort I just wrapped up a coding challenge involving Bubble Sort, one of the most fundamental algorithms in computer science. While modern languages like Python have highly optimized built-in sorting methods, implementing this from scratch is a great way to understand algorithm complexity and in-place memory manipulation. The Logic: Bubble Sort works by stepping through a list, comparing adjacent elements, and "swapping" them if they are in the wrong order. This process repeats until the largest values "bubble up" to the end of the array. Key Takeaways: Time Complexity: $O(n^2)$ – This makes it a great educational tool, though not the most efficient for massive datasets! Space Complexity: $O(1)$ – It’s an "in-place" algorithm, meaning it doesn't require extra storage. Pythonic Swapping: Used Python’s elegant tuple unpacking a[j], a[j+1] = a[j+1], a[j] to handle swaps without needing a temporary variable. It feels good to reinforce these core concepts. Onward to more complex O(n log n) algorithms! 🚀 #Python #Coding #Algorithms #SoftwareEngineering #ProblemSolving #ContinuousLearning #30daysofcode #Gemini
To view or add a comment, sign in
-
Day 13/60 Continuing Chapter 2- Flow Control Topic IV - Using Complex Decisions 1. AND Operator We know how to run or skip code based on a condition like age > 16 . 🧩Code age = 17 has_permit = True if age > 16 print("Can drive") 🖥️ Output Can drive What if we wanted to run or skip code depending on two conditions? Like age > 16 and then has_permit . The and operator allows us to run code only if both conditions age > 16 and has_permit are True . 🧩Code age = 17 has_permit = True if age > 16 and has_permit: print("Can drive") 🖥️ Output Can drive The and operator skips the code block if one or more conditions are False , like age > 18 . We can add as many conditions as we want, like here, where we can add another and , and then is_insured to complete the condition. 🧩Code age = 17 has_permit = True is_insured = True if age > 16 and has_permit and is_insured: print ("Can drive") 🖥️ Output Can drive 🧠Challenge of the day What will be the output of the following code if user inputs 1900 What will be the output of the following if user enters 1990 🧩Code year_input = input("Please enter a valid year: ") year = int(year_input) if year > 1900 and year < 2026: print("Valid entry") else: print("Invalid entry") This topic will be continued tomorrow… with OR Operator #python #programming #ai #bigtech
To view or add a comment, sign in
-
🚨 This mistake is increasing your memory usage without you realizing it I was using lists everywhere (wrong way) I didn’t think much about memory Everything worked fine… until my program started slowing down 🐢 Sometimes it even crashed on large data 😓 That’s when I learned about generators And it completely changed how I write code ⚡ 👉 Lists store all values in memory 👉 Generators create values one by one (on demand) 👉 Perfect for large data or streaming 🚀 Example: List ⛔ Stores full data → high memory Generator ✅ Yields data → low memory Result: Less memory usage + better performance + scalable code Lesson: If you are working with large data, don’t use lists blindly. Use generators. It will make your code more efficient. Do you use generators or still rely on lists? 🤔 #Python #Generators #Coding #Programming #Developers #TechLearning #Performance #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