Day 13 – Practice with Recursion, Loops, and String Logic in Python Day 13 was all about hands-on problem solving. I focused on strengthening my logical thinking by implementing common programming problems using functions, loops, recursion, and strings. What I practiced today: Recursion Concepts: Calculated the sum of N natural numbers using recursion Example: input = 5 → output = 15 Understood how recursive calls work and when to stop using base conditions Loop-Based Logic (Without Recursion): Printed N Fibonacci numbers using loops Learned why loops are more memory-efficient than recursion in some cases String Processing Problems: Found the frequency of each character in a string using dictionaries Counted occurrences of characters without using built-in methods Compared two strings and printed common characters Avoided duplicate counting using a checked/reference string Pattern & Combination Problems: Printed all possible character pairs from a given string Example: "abc" → ab, ac, bb, bc, ca, cb, cc Practiced nested loops to generate combinations List & String Manipulation: Reversed each string inside a list without using slicing Converted: ["apple", "banana", "orange", "mango", "grapes"] into reversed word format Key Takeaways: Improved understanding of nested loops and condition checks Learned how to avoid repeated computations Practiced writing logic without relying on shortcuts or built-in functions Strengthened confidence in solving interview-style problems Consistent practice like this is helping me think more clearly about how code actually works step by step. #Python #PythonPractice #ProblemSolving #Recursion #Loops #StringManipulation #LogicalThinking #DailyLearning #CodingPractice #ComputerScience
More Relevant Posts
-
🧠 Python Concept: List Comprehension Write powerful loops in one clean line. ❌ Traditional Way squares = [] for i in range(5): squares.append(i * i) print(squares) Output [0, 1, 4, 9, 16] ✅ Pythonic Way squares = [i * i for i in range(5)] print(squares) Same result, less code. ⚡ With Condition even_squares = [i * i for i in range(10) if i % 2 == 0] print(even_squares) Output [0, 4, 16, 36, 64] 🧒 Simple Explanation Imagine telling a robot: 👉 “Give me squares of numbers from 0–4.” 👉 Instead of repeating instructions, you give one rule. 👉 That rule = list comprehension. 💡 Why This Matters ✔ Shorter code ✔ Faster execution ✔ More readable loops ✔ Very Pythonic 🐍 Python often replaces multiple lines with a single elegant expression 🐍 List comprehensions are one of the most powerful examples of that philosophy. #Python #PythonTips #PythonTricks #AdvancedPython #List #ListComprehension #Tech #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Practice – Two Pointer Technique 💻 Today I practiced a simple but powerful Data Structures problem: Reversing an Array using the Two Pointer Approach 🔄 Instead of using extra space, we can reverse the array efficiently by using two pointers: 👉 One pointer at the start (left) 👉 One pointer at the end (right) We then swap the elements and move the pointers toward each other until they meet. ✨ Advantages ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) (No extra space required) 🐍 Python Implementation: arr=list(map(int,input("elements:").split())) left=0 right=len(arr)-1 while left<right: arr[left],arr[right]=arr[right],arr[left] left+=1 right-=1 print("Reversed array :",arr) 📌 Practicing these DSA fundamentals helps improve problem-solving skills and prepares us for coding interviews. #Python 🐍 #DSA 📊 #TwoPointerTechnique #CodingPractice 💡 #Programming 🚀 #LearningJourney 📚
To view or add a comment, sign in
-
-
🧠 Python Concept That Explains Function Closures: Late Binding Why does this print 3 3 3 instead of 0 1 2? 👀 funcs = [] for i in range(3): funcs.append(lambda: i) for f in funcs: print(f()) ❗ Output 3 3 3 🤔 The Reason: Late Binding 💻 Closures capture variables, not values. 💻 So all lambdas reference the same i (final value = 3). 💫 Simple Explanation 🧒 Imagine 3 kids pointing at a scoreboard 🧒 They don’t remember the score when they pointed. 🧒 They look at the board later. 🧒 Board changed → all see same number. ✅ Fix (Bind value early) funcs = [] for i in range(3): funcs.append(lambda i=i: i) for f in funcs: print(f()) ✔ Output 0 1 2 💡 Why This Matters ✔ Closures ✔ Async loops ✔ Callbacks ✔ GUI handlers ✔ Interview classic 🐍 Python closures capture variables, not snapshots 🐍 That’s why loop lambdas often surprise developers. 🐍 Understanding late binding removes a whole class of bugs. #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
Utilizing the Math Module for Square Roots and Factorials Modules in Python are essential for code organization and reusability, and the `math` module serves as a built-in resource that provides a variety of mathematical functions. When you import a module, you bring a toolkit of pre-defined functions, constants, and classes into your workspace, simplifying complex tasks without needing to rewrite code. In the example above, we leverage the `math` module to perform two mathematical operations: calculating the square root and finding the factorial. The `math.sqrt()` function efficiently computes the square root of a number, while `math.factorial()` finds the factorial of a given integer. These built-in functions illustrate how you can significantly simplify coding tasks by utilizing existing libraries. Importing a module is straightforward with the `import` keyword, and functions within the module are accessed via dot notation. This allows for easy calls like `math.sqrt()` and `math.factorial()` after importing `math`. Understanding this concept encourages the use of Python's built-in capabilities, enhancing both maintainability and readability of your code. Additionally, you can create your own modules. This feature lets you encapsulate related functions and classes, making your code reusable across different projects. Writing modular code not only keeps your main script clean but also facilitates collaboration, allowing others to navigate your code structure more easily. Quick challenge: What would you need to change in the code if you wanted to find the natural logarithm instead? #WhatImReadingToday #Python #PythonProgramming #Modules #CodeReuse #Programming
To view or add a comment, sign in
-
-
🧠 Python Concept: List Comprehension Write loops in one clean line 😎 ❌ Traditional Way numbers = [1, 2, 3, 4, 5] squares = [] for num in numbers: squares.append(num * num) print(squares) ✅ Pythonic Way numbers = [1, 2, 3, 4, 5] squares = [num * num for num in numbers] print(squares) 🧒 Simple Explanation Think of it like a shortcut formula 🧮 ➡️ Take each item ➡️ Apply logic ➡️ Store result — all in one line 💡 Why This Matters ✔ Less code, more clarity ✔ Faster to write ✔ Easy to read once you learn it ✔ Widely used in real projects ⚡ Bonus Example (With Condition) even_squares = [num * num for num in numbers if num % 2 == 0] print(even_squares) 🐍 Python is all about writing clean and expressive code 🐍 Master list comprehension = level up 🚀 #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
How do "try" and "except" work in Python for handling errors? In Python, errors can occur during program execution (called exceptions). If they are not handled properly, the program may stop unexpectedly. This is where try and except statements come in. 🔹 "try" Used to wrap the code that might raise an error. 🔹 "except" Used to handle the error if it occurs, preventing the program from crashing. Example: try: x = int(input("Enter a number: ")) print(10 / x) except ValueError: print("Invalid input") except ZeroDivisionError: print("Cannot divide by zero") Python also provides additional clauses to make error handling more powerful: ▪ "else" → runs only if no exception occurs ▪ "finally" → always runs (useful for closing files or cleaning resources) ▪ "raise" → allows developers to trigger custom exceptions Understanding exception handling is essential for writing reliable and robust Python applications. #Python #AI #DataScience #Analytics #Programming #MachineLearning #Instant
To view or add a comment, sign in
-
🧠 Topic: Mutable vs Immutable in Python Ever wondered why sometimes your data changes… and sometimes it doesn’t? 🤔 👉 In Python, objects are of two types: ✅ Mutable (can change after creation)Examples: list, dict, set a = [1, 2, 3] a.append(4) print(a) Output:[1, 2, 3, 4] ✅ (Changed) ❌ Immutable (cannot change after creation)Examples: int, string, tuple x = "hello" x.upper() print(x) Output:hello ❌ (Not changed) 💡 Why?Because immutable objects create a new value instead of modifying the original. 🎯 Real-life example:Mutable = Whiteboard (you can erase & rewrite)Immutable = Printed paper (you can’t change it) 👇 Quick Question:Is tuple mutable or immutable? Drop your answer in comments 👇 #Python #Coding #Learning #100DaysOfCode #Programming #Developers
To view or add a comment, sign in
-
Day 5 of #60DaysOfMiniProjects From generating QR codes to now decoding them — leveling up step by step. Today I built a QR Code Scanner using Python that reads a QR image and extracts the embedded data instantly. What this project does: • Accepts a QR image as input • Detects and decodes the QR code • Extracts hidden text/URLs • Handles errors gracefully Concepts I worked with: • Image processing using PIL • QR decoding with pyzbar • Exception handling • Writing cleaner, production-style code • Improving program reliability Now I’ve built both a QR Generator + QR Scanner — completing the full workflow cycle. Small projects. Real concepts. Daily progress. Consistency builds confidence. #Python #MiniProjects #BuildInPublic #CodingJourney #CSE #DeveloperGrowth #LearningInPublic
To view or add a comment, sign in
-
Day 17 – Strings, Lists & Practical Logic Building in Python Today’s session was a mix of real-world logic building and deeper practice with strings and lists in Python. I started with a simple electricity bill calculation program using conditional statements. It helped me understand how tier-based logic works in real-life scenarios and how to structure conditions properly using if-elif-else. Strings – More Practice Revised and practiced important string methods: upper() and lower() for case conversion isupper() and islower() for validation capitalize() vs title() replace() with control over number of replacements This reinforced how strings are immutable and how every operation returns a new modified string. Lists – Slicing & Methods in Depth Worked extensively on list operations and understood the difference between modifying and non-modifying methods. Slicing Practice: Normal slicing Step slicing Reverse slicing Skipping elements using step values List Methods Explored: append() → add single element extend() → add multiple elements from iterable insert() → add element at specific index remove() → remove first occurrence pop() → remove by index (returns removed value) clear() → empty the list index() → find position of element sort() → modifies original list sorted() → returns new sorted list reverse() → reverse list order join() → join list elements into a string I also observed: How insert() behaves with negative and out-of-range indexes Difference between sort() and sorted() How extend() works differently with list, tuple, and set Key Takeaways Understanding method behavior is more important than just memorizing syntax Some methods modify the original list, others return new values Real learning happens when testing edge cases Logic building is improving step by step Day 17 was more about strengthening fundamentals and building clarity in how Python handles data structures. #Python #PythonLists #PythonStrings #ProgrammingBasics #DataStructures #CodingPractice #DailyLearning #ProblemSolving #LearnToCode #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 50 Projects Challenge | Project #22/50 ⌨️ Project: Typing Speed Tester 🐍 Language: Python Developed a Python-based Typing Speed Tester that measures how fast and accurately a user can type a given sentence. This tool allows users to: ✔ Practice typing using a predefined sentence ✔ Measure the time taken to complete the sentence ✔ Calculate typing speed in Words Per Minute (WPM) ✔ Evaluate typing accuracy by comparing typed text with the original sentence The goal of this project was to understand how typing performance tools work and how programming can be used to measure real-time user performance. Through this project, I strengthened my understanding of: Measuring execution time using Python’s time module Comparing strings to detect typing errors Calculating performance metrics like WPM and accuracy Handling user input and interactive console programs Building simple productivity tools with Python Projects like this demonstrate how programming can be used to analyze performance and create useful everyday tools. Learning by building tools that measure real skills. 🚀 #50ProjectsChallenge #PythonProjects #StudentDeveloper #ProjectBasedLearning #LearningByDoing #SoftwareDevelopment
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