Computer Science Of Engineering

Simple and practical computer science tutorials, programming guides, and engineering concepts for students and beginners.

Breaking

Friday, April 25, 2025

Write a python program to count the number of vowels in a string (No control flow allowed).

 # Input string

text = "Hello World, this is Python!"


# Convert to lowercase and use list comprehension with count

vowels = "aeiouAEIOU"


# Use sum and map to count vowels without any loops or if

vowel_count = sum(map(text.count, vowels))


print("Number of vowels:", vowel_count)

Output:



No comments:

Post a Comment