Write a program, using a function main() that enter a string and a letter, count the number of occurrence of that letter in the string. Enter a string: Hello, how are you? Enter a char: o number of 'o' in "Hello, how are you?" is 3
Added by Jimmy P.
Close
Step 1
First, we need to prompt the user to enter a string and a letter. We can use the input() function to do this. Show more…
Show all steps
Your feedback will help us improve your experience
Anecia Mcmurrin-Bala and 54 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(Count the letters in a string) Write a function that counts the number of letters in a string using the following header: def countLetters(s): Write a test program that prompts the user to enter a string and displays the number of letters in the string.
PYTHON Write a program that accepts a sentence and calculate the number of letters and digits. Suppose the following input is supplied to the program: hello class! 123 Then, the output should be: LETTERS 10 DIGITS 3
Willis J.
In Python, write code to assign the number of characters in the string "rv" to a variable called "num_chars.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD