Day 5/365: Checking Armstrong Numbers in Python 🔢🧠 Today I worked on a classic number theory problem: checking whether a number is an Armstrong number. A number is an Armstrong number if the sum of its own digits each raised to the power of the number of digits is equal to the original number. For example: 153 has 3 digits 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 So 153 is an Armstrong number. What this function does: First, I store a copy of the original number so I can compare at the end. Then I find how many digits the number has using len(str(copy)). Inside the loop, I extract each digit, raise it to the power of the number of digits, and keep adding it to a running sum. Finally, I compare the sum with the original number: If they are equal, it’s an Armstrong number. Otherwise, it’s not. What I learned from this exercise: How to break a number down digit by digit using % 10 and // 10. How to combine math (powers) with loops and conditionals to implement a rule. The importance of keeping a copy of the original value when you are modifying it in a loop. Day 5 done ✅ 360 more to go. If you have any variations of this problem (like finding all Armstrong numbers in a range or handling user input with validation), share them—I’d love to try them out. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #ArmstrongNumber #NumberTheory #CodingJourney #LearnInPublic #AspiringDeveloper
Checking Armstrong Numbers in Python
More Relevant Posts
-
I used to think errors were just problems… now I’m learning they’re part of the design. Today’s Python MahaRevision ⚙️ Chapter 12: Advanced Python (Part 1) This chapter felt like moving from basics to writing more robust code: → Exception handling (try-except) → Raising exceptions → try with else & finally → global keyword → __name__ == __"main"__ → enumerate function → List comprehensions A lot of small concepts—but each one adds more control and clarity to how code behaves. Practice set done: Handled errors in programs, experimented with custom exceptions, used enumerate for cleaner loops, and practiced writing compact code using list comprehensions. Some parts were new, some a bit tricky… but overall it felt like leveling up from just writing code to writing better code. Still learning, still improving. #Python #LearningInPublic #CodingJourney #Programming #AdvancedPython
To view or add a comment, sign in
-
At this point, Python is starting to feel less like a language… and more like a toolkit. Today’s Python MahaRevision 🧠 Chapter 13: Advanced Python (Part 2) This chapter introduced some really powerful and practical concepts: → Virtual environments → pip freeze (managing dependencies) → Lambda functions → bin() method → format() function → map, filter, reduce It’s interesting how these tools make code shorter, cleaner, and more efficient—once you understand how to use them properly. Practice set done: Worked on applying lambda functions, transforming data using map/filter, experimenting with reduce, and managing environments and dependencies. Some concepts felt a bit abstract at first (especially map/filter/reduce)… but with practice, they started making more sense. Biggest takeaway: Better tools don’t just make coding easier—they change how you think about solving problems. Still exploring, still improving. #Python #LearningInPublic #CodingJourney #Programming #AdvancedPython
To view or add a comment, sign in
-
Day 18 revision done. Operators. If/Else. Match statements. While loops. For loops. Not just reading through notes this time actually writing the code out, making mistakes, fixing them and doing it again until it felt natural. And honestly? It's working. The things that confused me the first time around are starting to make sense now. I finally get why // and % are different. I understand why indentation is not optional in Python. I know when to use a while loop vs a for loop. Revision isn't glamorous. There's no big aha moment. It's just you sitting down, doing the work and trusting that repetition builds confidence. And slowly it is making sense It is finally sticking and guess what I'm happy. Because Python is one of the most amazing tools used in the data space and I'm out here learning it on my own. Day 19 is next. Let's keep going. #Python #100DaysOfCode #SelfTaught #GrowthMindset #DataAnalysis #W3schools
To view or add a comment, sign in
-
Managing Python environments shouldn’t be a nightmare. But for many — it still is. Here’s how to keep things clean, fast, and production-ready in 2026: 🛠️ Use uv or poetry to manage environments & dependencies. Faster, safer, and simpler than old-school pip+venv. ⚡ Speed matters – use polars, numpy, and numba to vectorize heavy loops. Even small tweaks can give 10× performance wins. 🧼 Lint + Format + Type-check = non-negotiable Ruff for linting Black for formatting Pyright or Pyrefly for fast type-checks 💡 Bonus tip: Use Typer to build CLIs in minutes. So clean, it feels like magic. 💬 What’s one Python setup rule you wish you knew earlier? #Python #CodeQuality #Productivity #DevTools #DataEngineering
To view or add a comment, sign in
-
-
Python Dunder Methods: Making code more "Pythonic" 🐍 I’ve been playing around with operator overloading today! Instead of writing a bulky function like add_packages(pkg1, pkg2), Python allows us to use the __add__ magic method. By defining __add__, I can simply use the + operator to combine two package objects. Cleaner syntax? Check. More readable? Absolutely. I also added __str__ to ensure that when I print the result, I get a clear, formatted summary of the dimensions and weight rather than a messy memory address. #Python #CodingTips #SoftwareDevelopment #ObjectOrientedProgramming #CleanCode
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟵/𝟯𝟬 Instead of forcing my old coding habits into Python, I’m leaning into how the language handles data natively. Why write four lines of code when you can write one? 1. 𝗧𝗵𝗲 𝗦𝘁𝗮𝗻𝗱𝗮𝗿𝗱 𝗪𝗮𝘆 (Looping & Appending): nums = [1, 2, 3, 4] squared = [] for n in nums: squared.append(n * n) 2. 𝗧𝗵𝗲 𝗠𝗼𝗱𝗲𝗿𝗻 Approach 🚀: squared = [n * n for n in nums] 👉🏻It’s cleaner, faster, and much more intuitive. These are the small details that make the Python journey so satisfying🤌🏻 At what point do you find List Comprehensions become too complex? Do you stick to them for simple one-liners, or use them for nested logic too? #Python #30daysofcode #CodingJourney #Day9 #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Python Series – Day 7: Loops in Python (for & while) Till now, we learned conditions (if-else) 💻 But what if we want to repeat something multiple times? 🤔 👉 That’s where Loops come in 🔥 🧠 What is a Loop? A loop is used to execute a block of code multiple times 🔁 for Loop Used when we know how many times to run the loop for i in range(5): print(i) 👉 Output: 0 1 2 3 4 🔄 while Loop Used when we don’t know how many times to run i = 0 while i < 5: print(i) i += 1 ⚠️ Important Concept 👉 Infinite Loop (Be careful!) while True: print("Hello") 🛑 Break Statement Stops the loop for i in range(10): if i == 5: break print(i) ⏭️ Continue Statement Skips current iteration for i in range(5): if i == 2: continue print(i) 🎯 Why are Loops Important? ✔ Automate repetitive tasks ✔ Save time & effort ✔ Used in almost every program ❓ Question for you: What will be the output? for i in range(3): print(i * 2) 👉 Comment your answer 👇 📌 Tomorrow: Functions in Python 🔥 #Python #Coding #DataScience #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
Most developers waste hours on bad code. All because they skip one simple thing. 🔥 How Python Functions Work 👇 Stage 1: Plan ──▶ Pick a task ──▶ Name your function Stage 2: Write ──▶ Use def keyword ──▶ Add your logic Stage 3: Input ──▶ Pass your values ──▶ Set parameters Stage 4: Run ──▶ Call the function ──▶ See the output Stage 5: Reuse ──▶ Call it again ──▶ Save more time Functions keep your code clean. They save time. They make fixing bugs easy. Write once. Use many times. That is the real power of Python. 💡 Have you written your first Python function yet? Drop a YES or NO below 👇 #Python #PythonBasics #LearnPython #CodingForBeginners
To view or add a comment, sign in
-
🚨 This behavior of Python might look like a BUG… but it isn’t actually. a = 10 b = 10 print(id(a)) print(id(b)) 👉 Same memory location 😲 “Why do we have two variables pointing to the same memory location?!” Here comes the second one and things get interesting 👇 a = [1, 2, 3] b = a b.append(4) print(a) # [1, 2, 3, 4] 🔥 👉 Hmmm… why did ‘a’ change?! 💡 Explanation: ⭐ id() returns the identity of an object ⭐ Python reuses memory locations for immutable values ⭐ For mutable objects however, there is no copying, just pointers! ⚠️ The misconception: Most people believe ‘=’ copies objects in variables. 👉 Nope! ✅ Solution: b = a.copy() Now the two variables are separate ✅ 🔥 Consequence: It can seriously mess up your program’s logic! Ever got caught by such a ghost bug in Python? 👇 #CodeWithSujith #Python #Programming #Coding #PythonTricks #LearnPython #PythonBeginner #100DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🐍 The most misunderstood line in Python is this: for item in [1, 2, 3]: Most developers think the for loop just "goes through the list". What it actually does: calls iter([1,2,3]) to get an iterator, then calls next() on it repeatedly until StopIteration is raised. That's the entire protocol. Once you understand that, generators click immediately. A generator function with yield IS an iterator — Python implements iter and next automatically. And the magic of yield is that the function pauses at each yield and resumes from there on the next call. Full guide: iterator protocol from scratch, generator functions vs expressions, yield from for delegation, lazy 5-stage file processing pipeline, context managers (enter/exit), @contextmanager, suppress, ExitStack, and send()/throw() for two-way generator communication. A generator expression uses 200 bytes. An equivalent list uses 8MB. For the same data. 📎 Free PDF. Zero pip installs — pure Python standard library. #Python #Generators #Iterators #ContextManagers #PythonProgramming #SoftwareEngineering #CleanCode #BackendDev #Programming
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
Good job, stay consistent