Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Python Count the repeated character in a string¶ Write a python program to coun

ID: 3751555 • Letter: #

Question

*Python

Count the repeated character in a string¶

Write a python program to count how many times each vowel (a, e, i, o, u) is repeated in a string.

Pseudocode:

PROMPT the user for a string
INITIALIZE vowel count variables var_a, var_e, var_i, var_o, var_u to zero
FOR EACH letter IN string
    IF the letter matches any of the vowels
        INCREMENT the coresponding vowel value by 1
PRINT the character count per vowel

Example:
Input:
“google”
Output:
        There are 0 instances of a in google.
        There are 1 instances of e in google.
        There are 0 instances of i in google.
        There are 2 instances of o in google.
        There are 0 instances of u in google.

Explanation / Answer

string=input("Enter string:")
var_a = var_e = var_i = var_o = var_u = 0
for cha in string:
if (cha == 'a'):
var_a += 1
elif (cha == 'e'):
var_e += 1
elif (cha == 'i'):
var_i += 1
elif (cha == 'o'):
var_o += 1
elif (cha == 'u'):
var_u += 1
print("There are %d instances of a in %s."%(var_a,string))
print("There are %d instances of e in %s."%(var_e,string))
print("There are %d instances of i in %s."%(var_i,string))
print("There are %d instances of o in %s."%(var_o,string))
print("There are %d instances of u in %s."%(var_u,string))

output:

Enter string:google
There are 0 instances of a in google.
There are 1 instances of e in google.
There are 0 instances of i in google.
There are 2 instances of o in google.
There are 0 instances of u in google.