🚀 Day 5/60 – If-Else Conditions (Make Decisions in Python) Your code shouldn’t just run. It should think and decide. That’s where if-else comes in 👇 🧠 What is If-Else? It helps your program make decisions based on conditions. ✅ Basic Example age = 20 if age >= 18: print("You can vote") else: print("You cannot vote") 👉 If condition is True → first block runs 👉 Else → second block runs 🔁 Multiple Conditions (elif) marks = 75 if marks >= 90: print("Grade A") elif marks >= 60: print("Grade B") else: print("Fail") ⚡ Real-World Example temperature = 35 if temperature > 30: print("It's hot") elif temperature > 20: print("Nice weather") else: print("It's cold") ❌ Common Mistake if age > 18 print("Adult") # ❌ Missing colon Correct: if age > 18: print("Adult") # ✅ 🔥 Pro Tip Indentation matters in Python 👇 if True: print("Hello") # ❌ Error if True: print("Hello") # ✅ 🔥 Challenge for today Write a program: 👉 Take a number 👉 Check if it is: • Positive • Negative • Zero Comment “DONE” when you solve it ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #LearnPython #PythonProgramming #Coding #Programming
If-Else Conditions in Python: Making Decisions
More Relevant Posts
-
👉 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
-
-
🚀 Day 7/60 – Functions in Python (Write Reusable Code Like a Pro) Imagine writing the same code 10 times… ❌ Now imagine writing it once and reusing it… ✅ That’s the power of functions 👇 🧠 What is a Function? A function is a block of code that runs when you call it. 🔹 Basic Function def greet(): print("Hello, World!") Call it: greet() 🔹 Function with Parameters def greet(name): print("Hello", name) greet("Adeel") 🔹 Return Values (Very Important) def add(a, b): return a + b result = add(5, 3) print(result) # 8 ⚡ Real Example def is_even(num): return num % 2 == 0 print(is_even(4)) # True ❌ Common Mistake def greet() print("Hello") # ❌ Missing colon Correct: def greet(): print("Hello") # ✅ 🔥 Pro Tip Functions make your code: ✅ Reusable ✅ Clean ✅ Easy to debug 🔥 Challenge for today Write a function: 👉 Takes a number 👉 Returns square of that number Example: Input: 4 → Output: 16 Comment “DONE” when you solve it ✅ Follow Adeel Sajjad if you’re serious about mastering Python 🚀 #Python #LearnPython #PythonProgramming #Coding #Programming
To view or add a comment, sign in
-
-
🚀 Day 4 of Learning Python Another productive day diving deeper into Python — today was all about control flow and strings 🔥 🔹 Loop Control Statements 1️⃣ Break – stops the loop immediately for i in range(5): if i == 3: break print(i) 2️⃣ Continue – skips the current iteration for i in range(5): if i == 3: continue print(i) 3️⃣ Pass – does nothing (placeholder for future code) for i in range(5): pass 🔹 Strings in Python 1️⃣ Length Function name = "Python" print(len(name)) # Output: 6 2️⃣ Indexing & Slicing text = "Hello World" print(text[0]) # H (indexing) print(text[0:5]) # Hello (slicing) 🔹 String Methods ✔️ Lowercase & Uppercase text = "Hello" print(text.lower()) # hello print(text.upper()) # HELLO ✔️ Strip (removes spaces) text = " Hello " print(text.strip()) # Hello ✔️ Replace text = "Hello World" print(text.replace("World", "Python")) ✔️ Startswith & Endswith text = "Hello World" print(text.startswith("Hello")) # True print(text.endswith("World")) # True 💡 Every day I’m getting closer to thinking like a programmer — small concepts, big impact. Consistency Day 4 ✅ Let’s keep growing! #Python #CodingJourney #LearnInPublic #Programming #Tech
To view or add a comment, sign in
-
🧠 Python Concept: * (Unpacking Operator in Functions & Lists) Write flexible code like a pro 😎 ❌ Traditional Way nums = [1, 2, 3] print(nums[0], nums[1], nums[2]) ❌ Problem 👉 Fixed length 👉 Not flexible ✅ Pythonic Way nums = [1, 2, 3] print(*nums) 👉 Output: 1 2 3 🧒 Simple Explanation Think of * like “unpacking a bag 🎒” ➡️ Takes all items out ➡️ Spreads them ➡️ Uses them individually 💡 Why This Matters ✔ Cleaner code ✔ Works with any length ✔ Very useful in functions ✔ Widely used in real projects ⚡ Bonus Examples 👉 Merge lists: a = [1, 2] b = [3, 4] merged = [*a, *b] print(merged) 👉 Function arguments: def add(x, y, z): return x + y + z nums = [1, 2, 3] print(add(*nums)) 🐍 Don’t handle items one by one 🐍 Unpack them smartly #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Python Concept: try-except-else-finally Handle errors like a pro 😎 ❌ Without Handling (Risky) num = int(input("Enter number: ")) print(10 / num) 👉 Crash if user enters 0 or invalid input ❌ ✅ Pythonic Way try: num = int(input("Enter number: ")) result = 10 / num except ValueError: print("Invalid input") except ZeroDivisionError: print("Cannot divide by zero") else: print("Result:", result) finally: print("Execution completed") 🧒 Simple Explanation Think of it like a safety system 🛡️ ➡️ try → Try doing something ➡️ except → Handle errors ➡️ else → Runs if no error ➡️ finally → Always runs 💡 Why This Matters ✔ Prevents crashes ✔ Handles real-world user input ✔ Cleaner error management ✔ Must-know for developers ⚡ Bonus Tip except Exception as e: print("Error:", e) 🐍 Don’t let your program crash 🐍 Handle errors smartly #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Python Concept: any() vs all() (Advanced Use) Write cleaner condition checks 😎 ❌ Traditional Way numbers = [2, 4, 6, 8] all_even = True for num in numbers: if num % 2 != 0: all_even = False break print(all_even) ❌ Problem 👉 Extra variables 👉 More lines 👉 Less readable ✅ Pythonic Way numbers = [2, 4, 6, 8] all_even = all(num % 2 == 0 for num in numbers) print(all_even) 🧒 Simple Explanation Think of: 👉 all() = “Everything must be True” ✅ 👉 any() = “At least one is True” ⚡ 💡 Why This Matters ✔ Cleaner conditions ✔ No flags needed ✔ Very readable logic ✔ Used in validations & filters ⚡ Bonus Examples names = ["Alice", "Bob", "Charlie"] print(any(name.startswith("A") for name in names)) 👉 Output: True nums = [1, 2, 3] print(all(num > 0 for num in nums)) 👉 Output: True 🐍 Think less, write smarter 🐍 Let Python handle logic #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
-
Day 18: Scope and Precision — The Limits of Logic 🌐 As your programs grow, you'll start having variables with the same names in different places. How does Python know which one to use? And when doing math, how many decimals can Python actually "remember"? 1. Local vs. Global Scope Think of Scope as the "area of visibility" for a variable. Global Scope: Variables defined at the top level (outside any function). They can be read from anywhere in your script. Local Scope: Variables defined inside a function. They only exist while that function is running. Once the function ends, the variable is deleted. 💡 The Engineering Lens: Avoid using too many Global variables. If every function can change a variable, it becomes a nightmare to track down bugs. Keep data "Local" whenever possible! 2. The LEGB Rule: Python’s Search Engine When you call a variable name, Python searches in a very specific order to find it. This is the LEGB rule: Local: Inside the current function. Enclosing: Inside any nested "parent" functions. Global: At the top level of the file. Built-in: Python’s pre-installed names (like len or print). 3. Precision: The Decimal Limit When you use a Float (a decimal number), Python has to fit that number into a fixed amount of memory. Maximum Precision: Python floats are typically "double-precision" (64-bit). This means they can hold about 15 to 17 significant decimal digits. The Default: When you perform a calculation, Python will show as many decimals as are relevant, but it stops being accurate after that 15–17 digit mark. 💡 The Engineering Lens: Because of this limit, 0.1 + 0.2 often equals 0.30000000000000004. If you are building a banking app or a scientific tool where you need infinite precision, don't use floats! Use Python’s decimal module instead. #Python #SoftwareEngineering #CleanCode #ProgrammingTips #DataPrecision #LearnToCode #TechCommunity #PythonDev
To view or add a comment, sign in
-
🚀 Day 6/60 – Loops in Python (Automate Repetition Like a Pro) Writing the same code again and again? ❌ Let Python do it for you ✅ That’s what loops are for 👇 🔁 What is a Loop? A loop lets you repeat a block of code multiple times. 🔹 1️⃣ For Loop (Most Used) for i in range(5): print(i) 👉 Output: 0 1 2 3 4 🔹 2️⃣ Loop Through List fruits = ["apple", "banana", "mango"] for fruit in fruits: print(fruit) 🔹 3️⃣ While Loop count = 0 while count < 5: print(count) count += 1 ⚡ Real Example for i in range(1, 6): print("Hello", i) 👉 Prints "Hello" 5 times ❌ Common Mistake (Infinite Loop) count = 0 while count < 5: print(count) ❌ This never stops! Correct: count += 1 🔥 Pro Tip Use range(start, stop, step) 👇 for i in range(1, 10, 2): print(i) 👉 1, 3, 5, 7, 9 🔥 Challenge for today Write a program: 👉 Print numbers from 1 to 10 👉 Print only even numbers Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #LearnPython #PythonProgramming #Coding #Programming
To view or add a comment, sign in
-
-
Logic in Python – Understanding and, or, and not! 🔗🐍 Programs aren’t just about calculations—they need to make decisions. That’s where logical operators come in. They let us combine multiple conditions and control the flow of our code. This session was all about mastering the three core logical operators in Python: and, or, and not. Here’s what I learned: --- 🔹 The and Operator · Returns True only if both operands are True. · Otherwise, it returns False. A and B True + True = True True + False = False False + True = False False + False = False ```python print((2 < 3) and (1 < 2)) # True and True → True print((5 > 3) and (2 > 5)) # True and False → False ``` --- 🔹 The or Operator · Returns True if at least one operand is True. · Only False if both are False. A B A or B True + True = True True + False = True False + True = True False + False = False ```python print(True or False) # True print(False or False) # False ``` --- 🔹 The not Operator · Reverses the boolean value. · not True → False · not False → True ```python print(not True) # False print(not False) # True ``` --- ✅ Key Takeaways: · Logical operators work with boolean values and return booleans. · and → all must be true · or → at least one true · not → flips the truth value · You can combine them with relational operators to build complex conditions. --- 💬 Let’s Discuss: Have you ever used and/or in a real project? What’s the most creative condition you’ve built with them? Drop your examples below! 👇 --- 🔖 #Python #LogicalOperators #CodingBasics #LearnToCode #ProgrammingLogic #NXTWave #TechJourney
To view or add a comment, sign in
-
🚀 Built a simple Python script to clean up my messy Downloads folder! We all download files daily, and things get cluttered fast. So I wrote a quick automation script using Python to organize files into folders like Images, Documents, Archives, etc. 💡 Here’s the code: ```python from pathlib import Path import shutil # Folder to organize source = Path("C:/Users/YourName/Downloads") # File type mapping folders = { ".jpg": "Images", ".png": "Images", ".pdf": "Documents", ".zip": "Archives", ".exe": "Installers" } for file in source.iterdir(): if file.is_file(): folder_name = folders.get(file.suffix.lower()) if folder_name: destination = source / folder_name destination.mkdir(exist_ok=True) shutil.move(str(file), destination / file.name) ``` ⚡ What it does: * Scans your Downloads folder * Detects file types * Creates folders automatically * Moves files to the right place Sometimes, small automations like this can save a lot of time and keep your system organized. #Python #Automation #Coding #Developers #Productivity #Backend
To view or add a comment, sign in
Explore related topics
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