Create a program that will accept a string. Count the length of the string and convert all vowels to upper case and all consonants to lower case. Count number of vowels and consonants in the string. Display all vowels and consonant characters found in the string and the index number of each vowel and consonant character.
Example:
Enter a string: the quick brown fox
String length is 19
Converted string in upper case and lower case: thE qUIck brOwn fOx
There are 5 vowels
Vowel characters are: e u i o o
Vowel characters can be found at index: 2 5 6 12 17
There are 11 consonants characters.
Consonant characters are: t h q c k b r w n f x
Consonant characters can be found at index: 0 1 4 7 8 10 11 13 14 16 18
input_string = input("Enter a string: ")
s_len = len(input_string)
vow_ch, vow_ind = "", ""
con_ch, con_ind = "", ""
count_vow, count_con = 0, 0
res_string = ""
for i in range(s_len):
if input_string[i].lower() in ("a", "e", "o", "u", "i"):
vow_ch += input_string[i].lower() + " "
vow_ind += str(i) + " "
count_vow += 1
res_string += input_string[i].upper()
elif input_string[i].isalpha():
con_ch += input_string[i].lower() + " "
con_ind += str(i) + " "
res_string += input_string[i].lower()
count_con += 1
else:
res_string += input_string[i]
print(f"\nString length is {s_len}")
print(f"Converted string in upper case and lower case: {res_string}")
print(f"\nThere are {count_vow} vowels")
print("Vowel characters are: " + vow_ch)
print("Vowel characters can be found at index: " + vow_ind)
print(f"\nThere are {count_con} consonants characters")
print("Consonant characters are: " + con_ch)
print("Consonant characters can be found at index: " + con_ind)
Comments
Leave a comment