Day 54 – Catching Multiple Exceptions One size doesn’t fit all — especially with errors 😅 Different errors need different fixes: try: value = int(input("Enter a number: ")) print(10 / value) except ValueError: print("That’s not a valid number!") except ZeroDivisionError: print("Can't divide by zero!") 🎯 Python lets you handle multiple exceptions gracefully. ✅ Better user experience ✅ Easier debugging ✅ Cleaner code logic 👉 Do you handle different errors separately in your code? #Python #CodeQuality #DebuggingTips
Handling Multiple Exceptions in Python
More Relevant Posts
-
Day 53 – Why Error Handling Matters in Python Bugs happen. Programs crash. But clean code doesn’t let users see that. That’s why we use error handling to prevent unexpected breakdowns 🧯 try: result = 10 / 0 print(result) except ZeroDivisionError: print("Oops! Can't divide by zero.") 🧠 Output: Oops! Can't divide by zero. 🔹 try → The risky part 🔹 except → What to do if something goes wrong Robust apps = happy users. Handle your errors before they handle you 😄 👉 Ever had a small error break a big project? #Python #ErrorHandling #Debugging #100DaysOfCode
To view or add a comment, sign in
-
🧪 Day 278: Testing Your Code with unittest Here’s the truth: good developers don’t just write code — they test it. Python’s unittest framework helps you verify your logic before it breaks in production (or worse… in front of your boss 😅). 👉 Let’s start simple: import unittest def add(a, b): return a + b class TestAdd(unittest.TestCase): def test_add(self): self.assertEqual(add(2, 3), 5) if __name__ == '__main__': unittest.main() 💡 Pro tip: Always test edge cases — those are the ones that usually break things. 🔹 Challenge: Write a test suite for your calculator script (addition, subtraction, multiplication, division). #Python #UnitTesting #CleanCode #LearnByDoing
To view or add a comment, sign in
-
💻 Day 275: Talking to Your Computer with os Today’s post is about one of Python’s oldest — but still coolest — superpowers: the os module. This is how your Python program literally talks to your computer — listing files, creating folders, or checking what directory it’s in. 👉 A simple intro: import os current = os.getcwd() print(f"You’re currently here: {current}") print("Files around you:") print(os.listdir(current)) This small piece of code helps Python navigate your system just like a person browsing through folders. 💡 Pro tip: Use os.path.exists() before performing risky file operations — it’ll save you from those “file not found” heartbreaks. 😅 🔹 Challenge: Write a script that checks if a file exists before trying to open it. #Python #OSModule #Automation #LearnPython
To view or add a comment, sign in
-
Python magic wand >>>Want to create "magic" APIs that respond to any method call? >>> __getattr__ enables dynamic attribute resolution. You no need to define every endpoint manually! __getattr__ intercepts any undefined attribute access, allowing you to create dynamic APIs that adapt to any method call pattern!
To view or add a comment, sign in
-
-
The Final Result! Output 👍 🔧 Features Implemented: ➕ Add Contact 🔍 Search Contact 📄 Display All Contacts ❌ Exit Option 📚 Uses Python dictionary to store name–number pairs
To view or add a comment, sign in
-
Just eliminated an entire process with 20 lines of Python 🐍 The problem: Manually renaming hundreds of student files to match registry conventions The old way: 2-3 hours of mind-numbing clicking The new way: Run script. Get coffee. Done. python # What used to take hours now takes seconds for file in folder: new_name = transform_to_standard(file) rename(file, new_name) sanity_restored += 1 Sometimes the best process is no process. #Python #Automation #RegistryLife #WorkSmarter
To view or add a comment, sign in
-
🗓️ Day 274: Time Travel in Python with datetime Ever needed to find what date falls 7 days from now? Or calculate how long it’s been since your last deadline? That’s where Python’s datetime module shines! It’s one of those tools that quietly powers everything — from logs and APIs to attendance systems and time-based automation. 👉 Here’s a tiny example to get you started: from datetime import datetime, timedelta # Get current time now = datetime.now() print(f"Right now: {now}") # Add 5 days future = now + timedelta(days=5) print(f"In 5 days: {future}") 💡 Pro tip: Combine datetime with formatted outputs (strftime) to create readable timestamps for reports or scheduled tasks. 🔹 Challenge for today: Write a script that calculates how many days are left until your next birthday 🎂. #Python #Datetime #CodeEveryday #LearnTogether
To view or add a comment, sign in
-
Is your Python function signature starting to look like a grocery list? In my latest video, I show how to reduce the number of arguments you pass around by using the Context Object Pattern. ✅ Cleaner APIs ✅ Easier testing ✅ Fewer bugs But... there's a catch. As I show in the video, this pattern can also make things worse if you use it the wrong way. 📺 Watch here → https://lnkd.in/eFq3GkT7 #Python #CleanCode #SoftwareDesign #ArjanCodes #DesignPatterns
To view or add a comment, sign in
-
-
To anyone interested in installing python dependencies in parallel and as fast as your network will let you, try using #uv https://lnkd.in/g4XbCxK4 ``` curl -LsSf https://astral[dot]sh/uv/install[dot]sh | sh uv venv --python 3.12 --seed source .venv/bin/activate time uv pip install torch # real 1m19.176s # user 0m27.393s # sys 0m8.284s ``` This saved me a lot of time.
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