🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Vowels are an essential part of English phonetics, and counting them in a given string is a common task in text analysis. This simple Python program demonstrates how to count the number of vowels in a string.
In the English language, the letters A, E, I, O, U (and sometimes Y) are considered vowels. The task here is to iterate over the string and count occurrences of these characters.
2. Program Steps
1. Define a string that contains a sequence of characters.
2. Create a list or set of vowels for reference.
3. Initialize a count variable to zero.
4. Loop through the string, checking each character to see if it is a vowel.
5. Increment the count for each vowel encountered.
6. Print the total count of vowels.
3. Code Program
# Define the string
input_string = "Python Programming is fun."
# Define the set of vowels
vowels = set('aeiouAEIOU')
# Initialize the vowel count
vowel_count = 0
# Loop through the string and count the vowels
for char in input_string:
if char in vowels:
vowel_count += 1
# Print the vowel count
print(f"The number of vowels in the string is: {vowel_count}")
Output:
The number of vowels in the string is: 6
Explanation:
1. input_string is the string in which we want to count vowels.
2. vowels is a set containing all uppercase and lowercase vowels.
3. vowel_count is initialized to 0 and is used to track the number of vowels found.
4. The for loop iterates over each character char in input_string.
5. The if condition checks if the current char is present in the vowels set.
6. For every vowel found, vowel_count is incremented by 1.
7. After the loop completes, vowel_count reflects the total number of vowels in input_string.
8. The print statement outputs this count, showing that there are 6 vowels in the string "Python Programming is fun.".
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment