1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Doss [256]
3 years ago
6

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:
Computers and Technology
1 answer:
otez555 [7]3 years ago
4 0

Answer:

The program written in python is as follows

def countchr(phrase, char):

     count = 0

     for i in range(len(phrase)):

           if phrase[i] == char:

                 count = count + 1

     return count

phrase = input("Enter a Phrase: ")

char = input("Enter a character: ")

print("Occurence: ",countchr(phrase,char))

Explanation:

To answer this question, I made use of function

This line defines function countchr

def countchr(phrase, char):

This line initializes count to 0

     count = 0

This line iterates through each character of input phrase

     for i in range(len(phrase)):

This line checks if current character equals input character

           if phrase[i] == char:

The count variable is incremented, if the above condition is true

                 count = count + 1

The total number of occurrence is returned using this line

     return count

The main method starts here; This line prompts user for phrase

phrase = input("Enter a Phrase: ")

This line prompts user for a character

char = input("Enter a character: ")

This line prints the number of occurrence of the input charcater in the input phrase

print("Occurence: ",countchr(phrase,char))

You might be interested in
Create an array to hold the rainfall values. Create a 2nd parallel array (as a constant) to hold the abbreviated names of the mo
Zarrin [17]

Answer:

#include <stdio.h>

int main()

{

//variable declaration

int low, high;

float lowRain, highRain, total, avg;

 

//array declaration

float rainfall[13];

char monthName[13][10] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

//get user input

for(int i=1; i<=12; i++)

{

printf("Enter the rainfall (in inches) for %s: ", monthName[i]);

scanf("%f", &rainfall[i]);

}

 

//display the monthly rainfall

printf("\nThe rainfall that was entered was:\n");

for(int i = 1; i<=6; i++)

printf("%s ", monthName[i]);

printf("\n");

for(int i = 1; i<=6; i++)

printf("%.1f ", rainfall[i]);

printf("\n");

for(int i = 7; i<=12; i++)

printf("%s ", monthName[i]);

printf("\n");

for(int i = 7; i<=12; i++)

printf("%.1f ", rainfall[i]);

 

//variable initialization

low = 1;

high = 1;

lowRain = rainfall[1];

highRain = rainfall[1];

total = 0;

 

//calculate the lowest, highest and averaage rainfall

for(int i=1; i<=12; i++)

{

if(lowRain>rainfall[i])

{

lowRain = rainfall[i];

low = i;

}

if(highRain<rainfall[i])

{

highRain = rainfall[i];

high = i;

}

total = total + rainfall[i];

}

 

avg = total / 12;

 

//display the result

printf("\n\nThe total rain that fell was %.1f inches", total);

printf("\nThe average monthly rainfall was %.1f inches.", avg);

printf("\nThe lowest monthly rainfall was %.1f inches in %s.", rainfall[low], monthName[low]);

printf("\nThe highest monthly rainfall was %.1f inches in %s.", rainfall[high], monthName[high]);

return 0;

}

4 0
3 years ago
Which of the following type of software is the most powerful for managing complex sets of data?
devlian [24]
Well i thinck the ancer is b
5 0
3 years ago
Read 2 more answers
What is active server page ?or why is it important?
Thepotemich [5.8K]
For Example,
If You Were Hosting Ark Survival And Suddenly The Server Was Off Then The Players Goes Off.The Server Is How We Connect To The Platform In Order To Do The Action Intended.
5 0
3 years ago
Gwen wants to adjust columns of text that contain money values. Which tab stop option should she choose?
Shtirlitz [24]

Gwen wants to adjust columns of text that contain money values. The tab in excel in the stop option that should she choose is: "The decimal Tab" (Option C)

<h3>

What is the Decimal Tab?</h3>

A Decimal Tab stop is used to align numbers around a decimal point. The decimal point remains in the same location regardless of the amount of digits.

When using this form of tab stop, the numbers must be aligned around a decimal character.

Learn more about excel:
brainly.com/question/25879801
#SPJ1

3 0
7 months ago
Suppose you want to sell your product to of one of the school canteen of El Salvador city thus you conducted study to one of the
Lyrx [107]

The interpretation of the table is that it shows that 45.12 percent of the respondents are in 16 years of age when likened to 12.20 percent who are 19 years old and 18.29 percent that are in 18 years of age.

<h3>What is the table about?</h3>

The table is one that shows the age profile for Filipino children from 0 to 4 years and above to 19 years,

Note that it is also made up of the largest age group making up from 10.1 to 10.7 percent as seen on the Philippine Statistics Authority (PSA).

Therefore, students that are in 16 years of age will have the ability to take in or consume products more than the older students as seen in El Salvador City.

Learn more about product  from

brainly.com/question/10873737

#SPJ1

4 0
2 years ago
Other questions:
  • What is the purpose of inserting SmartArt in a Microsoft Office program? (1 point)
    11·2 answers
  • Which term is used to describe the science of examining raw data, removing excess noise from the dataset, and organizing the dat
    15·1 answer
  • You are looking for a backup that copies only the files that have changes since the last full backup. Which of the following wil
    13·1 answer
  • Which best describes the differences between a resume and a CV?
    13·2 answers
  • FREE 100 POINTS + FIRTS AWNSER = BRAINIST
    8·2 answers
  • What feature should be used before a document is printed
    8·1 answer
  • Use the drop-down menus to complete the statements about changing mail options in Outlook.
    10·1 answer
  • Create a program that calculates the tip and total for a meal at a restaurant. Type the code into an IDLE IDE editor window and
    5·1 answer
  • What lets you do many things, like write book reports and stories?
    14·2 answers
  • What represents a user’s specific preferences?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!