Question

Write a program whose input is a string which contains a character and a phrase, and...

Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase.

Ex: If the input is:

n Monday

the output is:

1

Ex: If the input is:

t this is a sentence with many t's

the output is:

4

PLEASE WRITE USING PYTHON

0 0
Add a comment Improve this question Transcribed image text
Answer #1
s = input()
ch = s[0]
string = s[2:]
count = 0
for x in string:
    if(x==ch):
        count += 1
print(count)

Output:

n Monday Process finished with exit code 0

t this is a sentence with many ts Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Write a program whose input is a string which contains a character and a phrase, and...
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
  • Write a program whose input is a string which contains a character and a phrase, and...

    Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0...

  • Write a program whose input is a character and a string, and whose output indicates the...

    Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday, the output is: 1 Ex: If the input is: z Today is Monday, the output is: 0 Ex: If the input is: n It's a sunny day, the output is: 2 Case matters. Ex: If the input is: n Nobody, the output is: 0 n is different than...

  • Please do it with C++. Thanks:) Write a program that reads a string and a character...

    Please do it with C++. Thanks:) Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input. Sample run: Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.

  • Using C++ programming. Write a program that takes a string of input from the user and...

    Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the...

  • 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...

  • Python Write a program which reads in a string and an signifying the number times the...

    Python Write a program which reads in a string and an signifying the number times the string should be repeated. The program should then output the string N times. integer N, You can assume all input will be valid. Example: Enter a string: hello How many times to repeat? 5 hello hello hello hello hello Example: T Enter a string: goodbye Ty How many times to repeat? 32 goodbye goodbye [... goodbye 30 more times]

  • 4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n...

    4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n is the integer value in matrix B which is having the same index as that of the character taken in A). Solve this using 1D Block. Example: 1 2 4 3 e X a M Output String STR: pCCaaaaPPPeeXXXXaaaMM 4B. Write...

  • 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

  • 5.19 LAB: Contains the character Write a program that reads an integer, a list of words,...

    5.19 LAB: Contains the character Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list will always contain less than 20 words. Each word will always contain less than 10 characters...

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

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