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
Question
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
Solution 1
Here is a Python program that accomplishes the task:
def find_vowels_pairs(s):
vowels = 'AEIOU'
s = s.upper()
pairs = []
for i in range(len(s)-1):
if s[i] in vowels and s[i+1] in vowels:
pairs.append(s[i:i+2])
return pairs
s = input("Enter a string: ")
pairs = find_vowels_pairs(s)
print("Pair of vowels:", ', '.join(pairs))
print("No. of pair of vowels:", len(pairs))
This program works by iterating over the input string and checking each pair of characters. If both characters in the pair are vowels, the pair is added to the list of pairs. The number of pairs is then the length of this list.
Solution 2
Here is a Python program that accomplishes the task:
def find_vowel_pairs(input_string):
# Convert the string to uppercase
input_string = input_string.upper()
# Define the vowels
vowels = 'AEIOU'
# Initialize an empty list to store the vowel pairs
vowel_pairs = []
# Iterate over the characters in the string
for i in range(len(input_string) - 1):
# If the current character and the next one are both vowels, add them as a pair to the list
if input_string[i] in vowels and input_string[i+1] in vowels:
vowel_pairs.append(input_string[i:i+2])
# Print the vowel pairs and their count
print('Pair of vowels:', ', '.join(vowel_pairs))
print('No. of pair of vowels:', len(vowel_pairs))
# Test the function
find_vowel_pairs("BEAUTIFUL BEAUTIES")
This program first converts the input string to uppercase. Then it iterates over the characters in the string. If the current character and the next one are both vowels, it adds them as a pair to a list. Finally, it prints the vowel pairs and their count.
Similar Questions
Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.
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
#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.
letter countWrite a C program that will analyze a line of text and will print the number of words, the number of consonants, and the number of vowels in the text.Testcase:Input:Programming is fun!Output:3 // Number of words:11 // Number of consonants:5 // Number of vowels:
find the number of alphabet vowels and words in input using string
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.