Day 4/365: Counting Vowels and Consonants in a String 🔤🧠 Today I worked on a classic beginner-friendly problem in Python: counting how many vowels and consonants are present in a string. The logic I used was simple but powerful: 1. Start with a string (for example: "Hello"). 2. Loop through each character. 3. If the character is in the set of vowels (aeiouAEIOU), increase the vowel counter. 4. Otherwise, if it’s an alphabet and not a vowel, increase the consonant counter. 5. In the end, print the total number of vowels and consonants. What I liked about this exercise: It made me think carefully about conditions (if / elif) and how loops work. I learned why it’s important to handle only alphabetic characters, so spaces, commas, or digits don’t get counted as consonants by mistake. It’s a small step, but it builds the habit of thinking about edge cases and input validation. Day 4 done ✅ 361 more to go. If you have any interesting variations of this problem (like handling entire sentences or ignoring case and punctuation), share them with me—I’d love to try them out. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #StringManipulation #CodingJourney #LearnInPublic #AspiringDeveloper
Counting Vowels and Consonants in Python
More Relevant Posts
-
🚀 Stop writing the same code again and again; create a function once and reuse it forever! Function Creation Made Simple: Think of a function like a reusable recipe. Instead of cooking from scratch every time, you write the steps once and reuse them whenever needed. 👉 Example in Python: def greet(name): return f"Hello, {name}!" Now, calling greet("Aditi") instantly gives the following: Hello, Aditi! 🔑 Takeaway: Functions save time, reduce errors, and make your code cleaner. Write once, use forever. Catch you later. Stay tuned for more updates. #Coding #Python #LearningMadeSimple #Functions
To view or add a comment, sign in
-
-
Today I worked on an interesting string problem — counting how many times a substring appears in a string without using built-in methods like count(). At first, it seemed straightforward… until I realized an important twist 👇 👉 Built-in count() does not handle overlapping substrings So I implemented a manual sliding window approach: 🔹 Traverse the string from left to right 🔹 Extract substrings using slicing 🔹 Compare each slice with the target substring 🔹 Increment count when a match is found 💡 Example: String → ABCDCDC Substring → CDC There are 2 occurrences, not 1 — because overlapping is allowed. This small problem helped me understand: How string slicing works internally Why built-in functions aren’t always sufficient The importance of handling edge cases like overlapping 🧠 Key takeaway: Sometimes writing logic manually gives deeper insight than relying on shortcuts. Learning step by step and enjoying the process 🔥 #Python #CodingJourney #100DaysOfCode #ProblemSolving #DataStructures #Learning
To view or add a comment, sign in
-
🌟 New Blog Just Published! 🌟 📌 Fast Python Project Setup 2026 with uv, Ruff, Ty, and Polars 🚀 📖 Starting a new Python project used to feel like assembling a jigsaw puzzle before you could write any code. You had to pick an environment manager, a dependency locker, a formatter, a linter, and a...... 🔗 Read more: https://lnkd.in/dZDzhD8G 🚀✨ #uv #ruff #polars
To view or add a comment, sign in
-
Today's office discussion took an unexpected turn, diving deep into the nuances of loops. We began with a seemingly simple question: What’s the real difference between a for loop and a while loop? Initially, it seemed straightforward: - Use a for loop when you know how many times to iterate. - Use a while loop when you only know the condition, not the count. However, the conversation quickly evolved. We discovered that the difference goes beyond syntax; it’s about intent and control. Interestingly, despite their differences, Python allows us to make for and while loops behave similarly. For instance: - A for loop is driven by an iterator. - A while loop is driven by a condition check. You can even rewrite a for loop using a while loop by manually handling the iterator. Ultimately, it’s not about which loop is more powerful; it’s about how you approach the problem. Final insights: - For loop → cleaner and more readable when iteration is defined. - While loop → more flexible when termination is dynamic. - Under the hood, both are simply different methods of controlling flow. It's fascinating how a "beginner topic" can lead to a rich discussion about Python internals and abstraction layers. Sometimes, the simplest concepts reveal the deepest insights. #Python #Programming #SoftwareEngineering #LearningEveryday #CleanCode
To view or add a comment, sign in
-
🌟 New Blog Just Published! 🌟 📌 5 Free Ways to Host and Deploy Your Python Application Online 🚀 📖 Imagine you just finished a Python script that predicts bike rentals, and you want anyone on the internet to try it. You’ve already debugged locally, so the next step feels both exciting and...... 🔗 Read more: https://lnkd.in/d_7ywFbN 🚀✨ #freepythonhosting #pythondeployment #webapphosting
To view or add a comment, sign in
-
Beyond String Concatenation When I started, I used to concatenate strings the old-school way. It was messy, prone to errors, and hard to read The Problem: Using + requires manual type conversion (like str(21)) and gets confusing with all the extra quotes and spaces Solution: F-strings Introduced in Python 3.6, F-strings makes your code: ✅ Readable: You see the full sentence structure ✅ Fast: They are more efficient than older methods ✅ Flexible: You can perform math or call methods directly inside { } It’s a small concept, but it’s one of the easiest ways to make code look 10x more professional. #Python #30DaysOfCode #BCA #LearningInPublic #Day21 #JECRC Day 21/30
To view or add a comment, sign in
-
-
𝗔 𝗖𝗼𝗱𝗶𝗻𝗴 𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲 𝗶𝗻𝘁𝗼 𝗔𝗴𝗲𝗻𝘁𝗶𝗰 𝗨𝗜, 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗶𝘃𝗲 𝗨𝗜, 𝗦𝘁𝗮𝘁𝗲 𝗦𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗶𝘇𝗮𝘁𝗶𝗼𝗻, 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗿𝘂𝗽𝘁-𝗗𝗿𝗶𝘃𝗲𝗻 𝗔𝗽𝗽𝗿𝗼𝘃𝗮𝗹 𝗙𝗹𝗼𝘄𝘀 In this tutorial, we build the entire Agentic UI stack from the ground up using plain Python, without relying on external frameworks to abstract away the core ideas. We implement the AG-UI event stream to make agent behavior observable in real time, and we bring in A2UI as a declarative layer that allows interfaces to […] The post A Coding Deep Dive into Agentic UI, Generative UI, State Synchronization, and Interrupt-Driven Approval Flows appeared first on MarkTechPost. https://lnkd.in/e8VUGpiQ
To view or add a comment, sign in
-
-
🚀 Today I practiced Python by building a mini project Created a Number Guessing Game 🎯 What I worked on: • Variables & data types • Loops (while) • Conditional statements (if/elif/else) • Attempt tracking logic What I learned: Building something small helped me understand how logic and flow actually work, instead of just watching tutorials. Challenges I faced: • Managing loop conditions • Tracking attempts correctly Sharing a snippet of my code below 👇 Next: → Building a CLI To-Do List → Improving input validation Staying consistent and learning step by step. #Python #LearningInPublic #CodingJourney #BeginnerDeveloper
To view or add a comment, sign in
-
-
📌 Problem: Merge Strings Alternately 💡 Approach: Used a simple two-pointer / iteration technique to merge both strings character by character. First, iterate up to the minimum length of both strings and append alternately. Then, append the remaining characters from the longer string. ⚙️ Key Insight: Handle unequal string lengths separately Avoid index out-of-bounds by iterating till min(len(word1), len(word2)) ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) merg 📚 What I learned: String manipulation efficiently Handling edge cases when lengths differ #LeetCode #DSA #Coding #ProblemSolving #Python #SoftwareDevelopment #CodingJourney
To view or add a comment, sign in
-
Just solved “Second Largest Digit in a String” on LeetCode — and here’s the simple approach I followed 👇 Instead of overcomplicating it, I focused on clean thinking + Python basics: 🔹 Converted the string into a set → removes duplicates instantly 🔹 Filtered only digits using isdigit() 🔹 Stored them as integers in a list 🔹 Sorted the list → easy access to largest & second largest 🔹 Edge case check: if less than 2 digits → return -1 💡 Key takeaway: Sometimes the most optimal solution isn’t about complex algorithms — it’s about using the right built-in tools smartly. 🚀 What I’m improving with each problem: • Writing cleaner logic • Thinking in steps instead of rushing • Handling edge cases early Consistency > Complexity. #LeetCode #DSA #Python #ProblemSolving #CodingJourney #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
Since you are interested in variations to the solution, I'm going to suggest normalizing the data. This will help you avoid errors down the line. Basically, convert everything to lower case. Now inside of your loop, you can have a more straightforward validation check: if the character is in "aeiou", since we are no longer interested in uppercase letters.