Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 10PE
Program Plan Intro
Vowels and Consonants
Program Plan:
- • Declare a function named “vowelsCount()” that accepts a string “my_string” as input. Inside the function,
- ○ Create a counter variable “cnt1” to store the number of vowels in the string.
- ○ Use the “for” loop to process all the characters in the “my_string” to check for vowels.
- ○ Inside the “for” loop,
- ■ Check if the current character “ch” is the alphabet.
- ■ If so, then check if the current character “ch” is the vowel.
- ■ If condition is true, then increment the “cnt1” value by “1”.
- ○ After processing all the characters in the “my_string”, return the counter “cnt1” value.
- • Declare a function named “consonantsCount()” that accepts a string “my_string” as input. Inside the function,
- ○ Create a counter variable “cnt2” to store the number of consonants in the “my_string”.
- ○ Use the “for” loop to process all the characters in the “my_string” to check for consonants.
- ○ Inside the “for” loop,
- ■ Check if the current character “ch” is the alphabet.
- ■ If so, then check if the current character “ch” is not a vowel.
- ■ If the condition is true, then increment the “cnt2” value by “1”.
- ○ After processing all the characters in the “my_string”, return the counter “cnt2” value.
- • Declare a function named “main()”. In the “main()” function,
- ○ Get a string from the user and store it in the “my_string” variable.
- ○ Call the function “vowelsCount()” to count the vowels and pass “my_string” as input to the function and store the return count in “count1”.
- ○ Call the function “consonantsCount()” to count the consonants and pass “my_string” as input to the function and store the return count in “count2”.
- ○ Display “count1” and “count2” using the “print()” function.
- • In the last, call the function “main()” to execute the program.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Vowels and Consonants:Write a program with a function that accepts a string as an argument and returns thenumber of vowels that the string contains. The application should have another function that Programming Exercises 369 VideoNote The Vowels and Consonants problem 370 Chapter 9 More About Strings accepts a string as an argument and returns the number of consonants that the string contains. The application should let the user enter a string and should display the number of vowels and the number of consonants it contains.
*python codimg
C# language
MORSE CODE CONVERTERDesign a program that asks the user to enter a string and thenconverts that string to Morse code. Morse code is a code whereeach letter of the English alphabet, each digit, and variouspunctuation characters are represented by a series of dots anddashes. Table 8-9 shows part of the code.
Needs to be two labels, two text boxes and click button for conversion
The____ function returns the length of a string .
Chapter 8 Solutions
Starting Out with Python (4th Edition)
Ch. 8.1 - Assume the variable name references a string....Ch. 8.1 - What is the index of the first character in a...Ch. 8.1 - If a string has 10 characters, what is the index...Ch. 8.1 - Prob. 4CPCh. 8.1 - Prob. 5CPCh. 8.1 - Prob. 6CPCh. 8.2 - Prob. 7CPCh. 8.2 - Prob. 8CPCh. 8.2 - Prob. 9CPCh. 8.2 - What will the following code display? mystring =...
Ch. 8.3 - Prob. 11CPCh. 8.3 - Prob. 12CPCh. 8.3 - Write an if statement that displays Digit" if the...Ch. 8.3 - What is the output of the following code? ch = 'a'...Ch. 8.3 - Write a loop that asks the user Do you want to...Ch. 8.3 - Prob. 16CPCh. 8.3 - Write a loop that counts the number of uppercase...Ch. 8.3 - Assume the following statement appears in a...Ch. 8.3 - Assume the following statement appears in a...Ch. 8 - This is the first index in a string. a. 1 b. 1 c....Ch. 8 - This is the last index in a string. a. 1 b. 99 c....Ch. 8 - This will happen if you try to use an index that...Ch. 8 - This function returns the length of a string. a....Ch. 8 - This string method returns a copy of the string...Ch. 8 - This string method returns the lowest index in the...Ch. 8 - This operator determines whether one string is...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns a copy of the string...Ch. 8 - Once a string is created, it cannot be changed.Ch. 8 - You can use the for loop to iterate over the...Ch. 8 - The isupper method converts a string to all...Ch. 8 - The repetition operator () works with strings as...Ch. 8 - Prob. 5TFCh. 8 - What does the following code display? mystr =...Ch. 8 - What does the following code display? mystr =...Ch. 8 - What will the following code display? mystring =...Ch. 8 - Prob. 4SACh. 8 - What does the following code display? name = 'joe'...Ch. 8 - Assume choice references a string. The following...Ch. 8 - Write a loop that counts the number of space...Ch. 8 - Write a loop that counts the number of digits that...Ch. 8 - Write a loop that counts the number of lowercase...Ch. 8 - Write a function that accepts a string as an...Ch. 8 - Prob. 6AWCh. 8 - Write a function that accepts a string as an...Ch. 8 - Assume mystrinc references a string. Write a...Ch. 8 - Assume mystring references a string. Write a...Ch. 8 - Look at the following statement: mystring =...Ch. 8 - Initials Write a program that gets a string...Ch. 8 - Sum of Digits in a String Write a program that...Ch. 8 - Date Printer Write a program that reads a string...Ch. 8 - Prob. 4PECh. 8 - Alphabetic Telephone Number Translator Many...Ch. 8 - Average Number of Words If you have downloaded the...Ch. 8 - If you have downloaded the source code you will...Ch. 8 - Sentence Capitalizer Write a program with a...Ch. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Word Separator Write a program that accepts as...Ch. 8 - Pig Latin Write a program that accepts a sentence...Ch. 8 - PowerBall Lottery To play the PowerBall lottery,...Ch. 8 - Gas Prices In the student sample program files for...
Knowledge Booster
Similar questions
- Option #1: String Values in Reverse Order Assignment Instructions Write a Python function that will accept as input three string values from a user. The method will return to the user a concatenation of the string values in reverse order. The function is to be called from the main method. In the main method, prompt the user for the three strings.arrow_forwardC# language MORSE CODE CONVERTER Design a program that asks the user to enter a string and thenconverts that string to Morse code. Morse code is a code whereeach letter of the English alphabet, each digit, and variouspunctuation characters are represented by a series of dots anddashes. Table 8-9 shows part of the code.arrow_forwardHelparrow_forward
- A string is passed as argument to a function named hS, the function also returns a string which is the first half of the string given as argument, i.e. from index 0 to l/2 where l is the length of the string. Language: C++arrow_forwardQ: People often forget closing parentheses when entering formulas. Write a program that asks the user to enter a formula and prints out whether the formula has the same number of opening and closing parentheses. Q: Write a program that asks the user to enter a word and prints out whether that word contains any vowels. Q: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user’s string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string. Typical output is shown below: Enter your string: Qbert Q*ert!!! Q: Write a program that asks the user to enter a string s and then converts s to lowercase, removes all the periods and commas from s, and prints the resulting string. Q: Write a program that asks the user to enter a word and determines whether the word is a palindrome or not. A palindrome is a word that reads the same…arrow_forwardwrite programs date formarrow_forward
- Code must be in C++arrow_forwardC++ reverse string allow the user to enter a string, display the results short codearrow_forward// MovieGuide.cpp - This program allows each theater patron to enter a value from 0 to 4 // indicating the number of stars that the patron awards to the Guide's featured movie of the // week. The program executes continuously until the theater manager enters a negative number to // quit. At the end of the program, the average star rating for the movie is displayed. #include <iostream> #include <string> using namespace std; int main() { // Declare and initialize variables. double numStars; // star rating. double averageStars; // average star rating. double totalStars = 0; // total of star ratings. int numPatrons = 0; // keep track of number of patrons // This is the work done in the housekeeping() function // Get input. cout << "Enter rating for featured movie: "; cin >> numStars; // This is the work done in the detailLoop() function // Write while loop here //…arrow_forward
- // MovieGuide.cpp - This program allows each theater patron to enter a value from 0 to 4 // indicating the number of stars that the patron awards to the Guide's featured movie of the // week. The program executes continuously until the theater manager enters a negative number to // quit. At the end of the program, the average star rating for the movie is displayed. #include <iostream> #include <string> using namespace std; int main() { // Declare and initialize variables. double numStars; // star rating. double averageStars; // average star rating. double totalStars = 0; // total of star ratings. int numPatrons = 0; // keep track of number of patrons // This is the work done in the housekeeping() function // Get input. cout << "Enter rating for featured movie: "; cin >> numStars; // This is the work done in the detailLoop() function // Write while loop here //…arrow_forwardC++ Programmingarrow_forwardc code Screenshot and output is mustarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT