Question

Write a program in python that asks the user to input a sentence. The program will...

Write a program in python that asks the user to input a sentence.

The program will ask the user what two letters are to be counted.

You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence.

You are not allowed to use python built-in function "count()" or you'll get a Zero!

Output will show the sentence, the letter, and the number of times the letter appears in the sentence.

Sample Run:

Please enter a sentence: HELLO WORLD

Please enter letter 1: E

Please enter letter 2: L

The letter E occurs 1 time

The letter L occurs 3 time(s)

1 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE UPVOTE

This does not use the built in function count(), so you need not worry.

I have explained exerything within the codein the comments part.

Here is the input to the code:

= def count letter(): #defining function count letter sentence = input(Please enter a sentence:) # input the sentence lette=== RESTART: C:/Users/ns 200/AppData/ Local/Programs/ Python/Python37/xcxc.py Please enter a sentence: HELLO WORLD Please ent

Here is the output:

=== RESTART: C:/Users/ns 200/AppData/ Local/Programs/ Python/Python37/xcxc.py Please enter a sentence: HELLO WORLD Please ent

PLEASE UPVOTE.

PLEASE COMMENT IT YOU HAVE ANY DOUBTS

Add a comment
Know the answer?
Add Answer to:
Write a program in python that asks the user to input a sentence. The program will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special”...

    USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special” letter. The program should then ask the user to enter a single line sentence containing all lowercase letters and no punctuation, except for a period at the end. The program will then output the number of times that this letter appears in the sentence. Example: Enter a special letter: t Enter a sentence: here is my little sentence. Your letter appears 3 times. (t...

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • Python: Write a program that lets the user enter a string and displays the letter that...

    Python: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case. Create a list to hold letters based on the length of the user input Convert all letters to the same case Use a loop to check for each letter in the alphabet Have a variable to hold the largest number of times a letter appears, and replace the value when...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • Your Python program should perform the following three tasks: 1. After getting a word of input...

    Your Python program should perform the following three tasks: 1. After getting a word of input from the user (i.e., any string), your program should use a while (or for) loop to print out each of the letters of the word. Just remember that strings in Python start with element 0! 2. Your program should then use another loop to print out each of the letters of the (same) word in reverse order! 3. Ask the user for a letter...

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

  • Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they...

    Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they enter a period ("."). Your program should then print all of the words they entered including the period) on a single line separated by spaces. For example, Enter some words (. to stop): > hello > world hello world.

  • please write in python Write a program that asks for beginning and ending number. The program...

    please write in python Write a program that asks for beginning and ending number. The program generates a set of 20 random numbers between the numbers and displays a count of each number generated. Sample output Enter starting and ending number separated by comma: 5, 25 5 occurs 2 times 7 occurs 1 time 8 occurs 1 time 10 occurs 2 times 12 occurs 1 time 13 occurs 2 time 15 occurs 5 times 16 occurs 1 time 20 occurs...

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • in C++ Write a program that will take a sentence from the user and uses a...

    in C++ Write a program that will take a sentence from the user and uses a ​for loop​ to convert all lowercase characters to uppercase characters. Then output the converted sentence. Example, if the user enters “Hello World”, your program should output “HELLO WORLD”.​ Recall that the ASCII value of ‘A’ is 65 and the ASCII value of ‘a’ is 97. The ASCII value of ‘Z’ is 90 and the ASCII value of ‘z’ is 122. in c++… we can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT