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

Using Python version 2.7, design a program that prompts the user to enter a stri

ID: 3533775 • Letter: U

Question

Using Python version 2.7, design a program that prompts the user to enter a string.The program should then display the number of vowels and the number of consonants in the string. I am absolutely lost and don't even know how to start, any assistance would be appreciated.


I will also provide the pseudocode that was provided by the teacher, if it helps at all:


// main module

Module main()

    // Variables

    Declare String str

    Declare Integer index

    Declare Integer vowels = 0

    Declare Integer consonants = 0

    // Get input from the user.

    Display "Enter a string."

    Input str


    // Scan the string counting vowels and consonants.

    For index = 0 To length(str) - 1

        If isVowel(str(index)) Then

            Set vowels = vowels + 1

        Else If isConsonant(str(index)) Then

             Set consonants = consonants + 1

        End If

    End For

    // Display the results.

    Display "Vowels: " , vowels

    Display "Consonants: " , consonants

End Module

// The isVowel function returns True if the argument

// is a vowel, or False otherwise.

Function Boolean isVowel(String ch)

    Declare Boolean status // Flag

    // Convert the argument to uppercase.

    ch = toUpper(ch)

    // Is ch a vowel?

    If ch == "A" OR ch == "E" OR

       ch == "I" OR ch == "O" OR

       ch == "U" Then

        Set status = True

   Else

        Set status = False

    End If

    Return status

End Function

// The isConsonant function returns True if the argument

// is a consonant, or False otherwise.

Function Boolean isConsonant(String ch)

    Declare Boolean status // Flag

    // Is ch a letter?

    If isLetter(ch) Then

        // Is ch not a vowel?

        If NOT isVowel(ch) Then

            Set status = True

        Else

            Set status = False

        End If

    Else

        Set status = False

    End If

    Return status

End Function

Explanation / Answer


def main():

  

input_str=''

index=0

vowels = 0

consonants = 0

  

  

input_str=raw_input('Input a string:')

  

for x in input_str:

if isVowel(x):

vowels = vowels + 1

elif isConsonant(x):

consonants = consonants + 1

  

  

  

print( "Vowels: " +str(vowels))

print ("Consonants: " +str(consonants))




def isVowel(ch):

status=True

ch = ch.upper()

  

if ( ch == "A" or ch == "E" or ch == "I" or ch == "O" or ch == "U"):

status = True

else:

status = False

  

return status



def isConsonant(ch):

status=True

  

if ch.isalpha():

  

if not( isVowel(ch) ):

status = True

else:

status = False

  

else:

status = False   

return status

if __name__ == '__main__':

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote