Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.Input: roboticsOutput: ROBOTICSNumber of vowels: 3
Question
Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.Input: roboticsOutput: ROBOTICSNumber of vowels: 3
Solution
Here is a Python class that accomplishes this:
class StringManipulator:
def __init__(self, input_string):
self.input_string = input_string
def convert_to_uppercase(self):
return self.input_string.upper()
def count_vowels(self):
vowels = ['a', 'e', 'i', 'o', 'u']
count = 0
for char in self.input_string:
if char.lower() in vowels:
count += 1
return count
# Create an instance of the class
manipulator = StringManipulator("robotics")
# Convert to uppercase
uppercase_string = manipulator.convert_to_uppercase()
print("Uppercase string: ", uppercase_string)
# Count vowels
vowel_count = manipulator.count_vowels()
print("Number of vowels: ", vowel_count)
This class, StringManipulator, takes a string as input when an instance is created. It has two methods: convert_to_uppercase and count_vowels. The convert_to_uppercase method returns the input string converted to uppercase. The count_vowels method counts the number of vowels in the input string and returns the count.
Similar Questions
Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.
#Write a Python function count_vowels(text) that takes a string as input and returns the count of vowels (a, e, i, o, u) in the input string, ignoring case.
Q) Write a program to input a string and convert it into uppercase and print the pair of vowels and number of pair of vowels occurring in the string. Example: Input: "BEAUTIFUL BEAUTIES " Output : Pair of vowels: EA, AU, EA, AU, IE No. of pair of vowels: 5
find the number of alphabet vowels and words in input using string
Read any string and display the vowels
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.