Exercise 8-3 Encapsulate

fruit = "banana"
count = 0
for char in fruit:
if char == "a":
count += 1
print(count)


This code takes the word "banana" and counts the number of "a"s. Modify this code so that it will count any letter the user wants in a string that they input. For example, if the user entered "How now brown cow" as the string, and asked to count the w's, the program would say 4.

Put the code in a function that takes two parameters-- the text and the letter to be searched for. Your header will look like def count_letters(p, let) This function will return the number of occurrences of the letter.
Use a main() function to get the phrase and the letter from the user and pass them to the count_letters(p,let) function. Store the returned letter count in a variable. Print "there are x occurrences of y in thephrase" in this function.
Screen capture of input box to enter numbeer 1

Answers

Answer 1

Answer:

python

Explanation:

def count_letters(p, let):

   count = 0

   for char in p:

       if char == let:

           count += 1

   print(f"There are {count} occurrences of {let} in the phrase {p}")

def main():

   the_phrase = input("What phrase to analyze?\n")

   the_letter = input("What letter to count?\n")

   count_letters(the_phrase, the_letter)

main()


Related Questions

Which of the following queries can have a fully Meets result?

Answers

Answer: we need the awnser key

Explanation:

Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10 factorials (from 0 to 9) with the corresponding number. Remember that the factorial of a number is defined as the product of an integer and all integers before it. For example, the factorial of five (5!) is equal to 1*2*3*4*5

Answers

Answer:

Following are code of factorial in python language

def factorial(n): # function

   result=1 #variable

   for x in range(2,n+1): #iterating the loop

       result=result*x  #storing result

   return result #return result

for n in range(10): #iterating loop

   print(n,factorial(n)) #print factorial

Output:

Following are the attachment of output

Explanation:

Missing information :

In the question the information is missing the code is missing which we have to correct it following are the code that are mention below.

def factorial(n): # function

   result=1 #variable

   for x in range(       ): #iterating the loop

       result=  #storing result

   return  #return result

for n in range(  ): #iterating loop

   print(n,factorial(n)) #print factorial

Following are the description of code

We have create a function factorial  in this we have pass the one parameter i.e "n".In the for loop we have pass 2,n+1 which has been used to iterating the loop calculating factorial and string the result in the result variable In the main function we have pass the range on which we have to calculated the factorialFinally the print function will print the factorial .

Following are the attachment snip of code in the python language

Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10
Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10

By filling in the blanks to make the factorial function return the factorial of n, we have the following.

def factorial (n):

 result = 1

 for x in range(2, n+1):

   result = result*x

 return result

for n in range(10):

 print(n,factorial(n))

The math module in Python includes a number series of mathematical operations that may be easily done using the module. The math . factorial() function computes the factorial of a given number.

To write the code perfectly and fill in the blanks:

We created a math factorial function with n parameterThis code is being passed through the iterating loop 2,n+1 for calculation. We string the result, perform the range, and print out the result using the print formula.

CODE:

def factorial (n):

 result=1

 for x in range(2, n+1):

   result = result*x

 return result

for n in range(10):

 print(n,factorial(n))

RESULT:

0 1

1 1

2 2

3 6

4 24

5 120

6 720

7 5040

8 40320

9 362880

Therefore, we can conclude that we've understood how to write the factorial function code in python.

Learn more about python coding here:

https://brainly.com/question/1351889?referrer=searchResults

Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10

what gases are involved in the process of respiration​

Answers

Answer: (O(2)), nitric oxide (NO), and carbon dioxide (CO(2))

Explanation:

please I need help.
Select the correct answer. of the four email features listed below, which is the most important?
O A. the To address
O B. the Bcc address
OC. the attachments
O D. the domain name

Answers

Answer:

The answer is the "TO address"

Explanation:

i just took the test and got it right sooooooo

Answer: A “The To adress”

Explanation:

got it right

which of the following file formats cannot be imported using Get & Transform

Answers

Answer:

The answer to this question is given below in the explanation section.

Explanation:

In this question, the given options are:

A.) Access Data table  

B.)CVS  

C.)HTML  

D.)MP3

The correct option to this question is D- MP3.

Because all other options can be imported using the Get statement and can be further transformed into meaningful information. But MP3 can not be imported using the GET statement and for further Transformation.

As you know that the GET statement is used to get data from the file and do further processing and transformation.

writer an obituary about macbeth​

Answers

Answer:

hi

Explanation:

A/an is a series of instructions or comands that computers follows used to create software

Answers

Answer:

Program

Explanation:

All computers have to follow a program to operate. Without a program, computers would not do what they are capable of today, and computers most likely wouldn't work.

Hope this helps! :)

The percentage of the audience with TV sets turned on that is watching a particular program is known as the ____________________.

Answers

Answer:

Share.

Explanation:

Social media publishing also known as broadcasting, can be defined as a service that avails end users the ability to create or upload web contents in either textual, audio or video format in order to make them appealing to a target audience.

Thus, these multimedia contents are generally accessed by end users from time to time through the use of various network-based devices and television set. As users access these contents, they're presented with the option of sharing a particular content with several other people a number of times without any form of limitation.

Additionally, the demographic or amount of audience (viewers) that a television show or program is able to get to watch at a specific period of time is generally referred to as share.

Hence, the percentage of the audience with TV sets turned on that is watching a particular program is known as the share.

For example, the percentage of the audience tuned in to watch a champions league final on a Saturday night, 8:00pm via their television set.

g Deliverables: 1.Referencing the Arduino attachInterrupt() documentationand the provided code, what does the attachIntterupt() function call on line 19 do, and how does that work with the magnet_detected() function

Answers

Answer:software routine that hardware invokes in response to an interrupt.

Explanation:

Time complexity gives a rough idea of how long it will take for an algorithm to execute

based on two things: the size of the input it has and the amount of steps it takes to complete,

whereas space complexity is also the amount of memory required to execute an algorithm based

on the size of input it has or given.

Using mathematical notations or diagrams critically explain the time and space complexity of the

code below. 10 marks

int a = 0;

for (i = 0; i < N; i++) {

for (j = N; j > i; j--) {

a = a + i + j;

}

}​

Answers

Answer:

Explanation:

O(N*N) or O(N2).

Explanation:

The time complexity can be measured by caculating the number of times the loop will execute.

The above code runs total no of times

= N + (N – 1) + (N – 2) + … 1 + 0

= N * (N + 1) / 2

= 1/2 * N^2 + 1/2 * N

O(N^2) times.

Thus Time complexity is O(N*N) or O(N2).

When i=0, it will run 0 times.

When i=1, it will run 1 times.

When i=2, it will run 2 times and so on.

So the time complexity will be O(N*N) or O(N2).

The function O(n2) has a complexity that is proportional to the square of the input size.

O(n2) with 2 total iterations.

O(N^2) is for → 2 nested “for loops”

We usually want to know how many steps an algorithm will take for an input of size ‘N' when calculating complexity.

This example contains two ‘for' loops, each of which will execute ‘N' times for each element ‘N'. As a result, it will run N2 times in total. In large O notation, we'd state the complexity of this algorithm is O(N2).

Time Complexity:

The amount of time it takes an algorithm to finish a computation.

What factors contribute to the complexity of time?

Looping (for, while)

Big O Notation:

The language and metric we use to describe how long an algorithm takes to run.

O(n²) Quadratic Time

Two nested loops are involved.

Each item from two different collections must be compared to one another.

Space Complexity:

Space complexity is the measurement of memory (space) that an algorithm requires, similar to time complexity.

What determines the complexity of space?

Variables

Allocations

Space Complexity: O(1) space

Because of the nested for loops The time complexity is going to be quadratic.

As a result, the Space Complexity will be O(1) space.

Worst case space complexity: O(1)

Hence,

Time Complexity: O(n²)

Space Complexity: O(1)

why are microwave antennas placed on top

Answers

Microwave transmission towers can also be placed strategically on rooftops, hills and even mountains to make them as efficient as their counterparts but not as expensive. This is why it's no wonder why more companies are now replacing their old systems with microwave antennas.

What does the effect of having more computers running mining software have on the security of the Bitcoin network?

Answers

Answer:

GPU mining itself isn't a danger to your PC—it's the mileage. Since most GPUs rely on attached or auxiliary fans, these parts can degrade faster during periods of sustained use. ... When managed properly, prolonged computational activity like cryptomining and gaming shouldn't degrade your GPU's physical integrity.

What is displayed in the alert dialog box after the following code is executed? var scores = [70, 20, 35, 15]; scores[scores.length] = 40; alert("The scores array: " + scores);

Answers

Answer:

The scores array: 70,20,35,15,40

Explanation:

I will explain the code line by line:

var scores = [70, 20, 35, 15];  

The above statement declares and assigns values to an array named scores

scores[scores.length] = 40;  

The above statement uses length to set the length of the scores array. It sets the last element of the scores array to 40. So this means 40 is set as the last element of scores.

scores.length returns the length of the scores array i.e. 4 as there are 4 elements in scores array 70,20,35,15

So the statement becomes:

scores[4] = 40;

This assigns value 40 to the 4th index of the scores array. Do not confuse 4th index with 4th element of the array because array element location starts from 0. So scores[4] does not mean 4th element but scores[4] means 4th index position of scores array. This makes 5th element of scores. So set the element 40 as 5th element at 4th index of scores.

alert("The scores array: " + scores);

This displays an alert box with the following message:

The scores array: 70,20,35,15,40

explain the fundamental Components of a Programming Language
can u answer in 8 lines

Answers

Answer:

1. Syntax: Syntax is the structure of a programming language which includes rules for constructing valid statements and expressions.

2. Data Types: Data types are used to define the type of data that is stored in a variable.

3. Variables: Variables are used to store data values.

4. Operators: Operators are used to perform operations on variables and values.

5. Control Structures: Control structures are used to control the flow of a program.

6. Functions: Functions are used to group related code into a reusable block.

7. Libraries: Libraries are collections of functions and data structures that can be used in a program.

8. Comments: Comments are used to document code and make it easier to understand.

Explanation:

Select the correct answer from each drop-down menu. What data types can you suggest for the given scenario? Adja is working in a program for the school grading system. She needs to use a(n) (First drop down) to store the name of the student and a(n) array of (Second drop down) to store all the grade of each subject of each student.
Options for the first drop down are- A. Integer, B.String, C.Character.
Options for the second drop down are- A.Floats, B.Character, C.String.

Answers

Based on the given scenarios, the data types that would be best suited for each is:

C. Character.A. Floats

What is a Data Type?

This refers to the particular type of data item that is used in order to define values that can be taken or used in a programming language.

Hence, it can be seen that based on the fact that Adja is working in a program for the school grading system, she would need to use a character to store the name of the student and a float to store all the grades of each subject of each student because they are in decimals.

With this in mind, one can see that the answers have been provided above.,

In lieu of this, the correct answer to the given question that have been given above are character and floats.

Read more about data types here:

https://brainly.com/question/179886

#SPJ1

Answer:

A- String

B- Character

What is the new programming language for developing iOS and Mac app

Answers

Answer:

Swift

Explanation:

I'm not sure about new, but IOS developers have been using Swift ever since the begining of time!


simple machines reduce the amount of work necessary to perform a task.
true or false?

Answers

True.

Simple machines are devices that are used to make work easier. They can reduce the amount of force, or effort, required to perform a task by increasing the distance over which the force is applied, or by changing the direction of the force. Examples of simple machines include levers, pulleys, wheels and axles, inclined planes, wedges, and screws. By using simple machines, the amount of work required to perform a task can be reduced.

List the invoice number and invoice date for each invoice that was created for James Gonzalez but that does not contain an invoice line for Wild Bird Food (25lb).

Answers

Answer:

Derive FROM invoice_transaction, invoice_details, item_details

and JOIN customer_details  ON (invoice_transaction.CUST_ID = customer_details.CUST_ID  AND customer_details.FIRST_NAME = 'James'   AND customer_details.LAST_NAME  = 'Gonzalez')

Explanation:

The following details will be there in the invoice

item_details rep_details invoice_details customer_details invoice_transaction

 Derive FROM invoice_transaction, invoice_details, item_details

and JOIN customer_details  ON (invoice_transaction.CUST_ID = customer_details.CUST_ID  AND customer_details.FIRST_NAME = 'James'   AND customer_details.LAST_NAME  = 'Gonzalez')

With clear examples, describe how artificial intelligence is applied in fraud detection

Answers

Answer:

AI can be used to reject credit transactions or flag them for review. Like at Walmart

Explanation:

I work with AI, i know what i'm talking about.

Identify the fallacy (if there is one) committed in the following passage: “In America the people appoint the legislative and the executive power and furnish the jurors who punish all infractions of the laws. The intuitions are democratic, not only in their principle, but in all their consequences. The people are therefore the real directing power.”

Ad Hominem
Tu Quoque
Appeal to Popularity
Appeal to Ignorance
No Fallacy In Passage

Answers

Based on the excerpt, we can logically deduce that there is: D. No Fallacy In Passage.

The types of fallacy.

In English literature, there are different types of fallacy and these include the following:

Appeal to authoritySlippery slopeHasty generalizationsAd HominemAppeal to Popularity (Ad populum)

Based on the excerpt, we can logically deduce that there is no fallacy In the passage because the statement isn't a false belief or based on illogical arguments and reasoning.

Read more on fallacy here: https://brainly.com/question/1395048

#SPJ1

Better Design Furniture has imported three refurbished medium sized electricity generators. The manager, Sam, was advised that the maximum running time for each generator is eight (8) hours. This is ideal for the company because the plant has to run for a complete twenty four hour period. With three generators running for eight hours each, this equates to twenty four (24) hours. Sam is now in dire need of a circuit that will start-up and shutdown each generator at different eight hour intervals.
According to Sam, the generators should work as follows: • Generator A 12:00 AM - 8:00 AM

• Generator B 8:00 AM - 4:00 PM • Generator C 4:00 PM - 12:00 AM
Sam has recruited your group as interns with the responsibility of designing the system that will execute the above functions. In designing the system, the group should ensure that generators are not allowed to run simultaneously, as this will result in serious damages to Sam’s equipment. In addition, there should be a disable switch which disables the power coming from the generators and enables the use of the Jamaica Public Service’s electric to power the equipment. This is necessary for the technicians to service the generators.
NB: Your counter/counting system should count in minutes and hours that is no need to worry about the seconds.

Answers

thx for the points but anyways how much v buck do you have pls give me some

Describe what test presentation and conclusion are necessary for specific tests in IT testing such as

-resource availability
-environment legislation and regulations (e.g. disposal of materials)
- work sign off and reporting ​

Answers

For specific tests in IT testing, the following elements are necessary.

What are the elements?

1. Test Presentation  -   This involves presenting the resources required for the test, ensuring their availability and readiness.

2. Conclusion  -   After conducting the test, a conclusion is drawn based on the results obtained and whether the objectives of the test were met.

3. Resource Availability  -   This test focuses on assessing the availability and adequacy of resources required for the IT system or project.

4. Environment Legislation and Regulations  -   This test evaluates compliance with legal and regulatory requirements related to environmental concerns, such as proper disposal of materials.

5. Work Sign Off and Reporting  -   This includes obtaining formal approval or sign off on the completed work and preparing reports documenting the test outcomes and findings.

Learn more about IT testing at:

https://brainly.com/question/13262403

#SPJ1

what is the use of buffer?​

Answers

Answer:

pH buffer or hydrogen ion buffer) is an aqueous solution consisting of a mixture of a weak acid and its conjugate base, or vice versa. ... Buffer solutions are used as a means of keeping pH at a nearly constant value in a wide variety of chemical applications.

Explanation:

there is your answer i got this one correct

hope it is helpful

Answer:

Limits the pH of a solution

Explanation:

A P  E X

What is Accenture's approach when it comes to helping our clients with security?​

Answers

Answer: Once actual project work starts, the CDP approach is implemented across all active contracts, helping Accenture client teams work with clients to drive a security governance and operational environment that addresses the unique security risks of each client engagement.

Explanation: Hopefully this helps you (Don't know if this is the right answer pls don't report if it is the wrong answer)

Meg logs into her email account without entering her user ID and password manually every time. She also finds results from search engines that are relevant to the place where she lives. Meg is aware that her personal information is not safe. What steps should Meg take for a safer browsing experience?
Meg should disable
of sensitive information such as her username and passwords. She should also disable the option to track her
in her web browser.
Reset

Answers

Answer: auto completion

Location

Explanation:

Based on the information given, Meg should disable (auto completion) of sensitive information such as her username and passwords and she should also disable the option to track her (location) in her web browser.

When auto completion is disabled, then she will have to enter her user ID and password manually every time she wants to login. Also, disabling the option to track her location will help in safeguarding her personal information.

What additional hindrances do criminal investigators face when dealing with computer crimes aside from the obvious struggle with the ever-changing technological world?​

Answers

Answer:hackers

Explanation:

1. Which of the following is a result of a successful negotiation?
Mediation
Win-win outcome
Conflict resolution
Consensus

Answers

Maybe a Win win outcome
I guess its Win-win outcome.
Thank you!

4. Digital eye strain happens because your eyes
O A. are bad and need glasses.
O B. dry out.
OC. follow and repeat the same path.
O D. must squint to read the screen

Answers

Answer:

B. dry out.

Explanation:

Digital eye strain happens because your eyes dry out.

what's another name for white -colored wire?
A. grounded conductor
B.Grounding conductor
C.Hot
D.Hot neutral

Answers

Answer:

A

Explanation:

A. The correct answer is A. "Grounded conductor" is another name for a white-colored wire. It is also commonly referred to as a neutral wire.

Answer:A. grounded conductor. I hope this helps

Explanation:

The correct answer is A. Grounded conductor. The grounded conductor is also commonly referred to as the neutral wire and is typically color-coded white

A. Grounded conductor is another name for white-colored wire. The grounded conductor is also commonly referred to as the neutral wire, which carries current back to the source. It is distinguished from the hot wire which carries the current to the loads. The grounding conductor, on the other hand, is typically green or bare and serves to ground the system for safety purposes

which of the following is a personal benifit of earning a college degree?
A) you have more friends
B) you are more likely to exercise
C) you are more likely to vote for the right candidate.
D) you have a longer life expectancy

Answers

Answer:

you have a longer life expectancy

Explanation:

Other Questions
Given the triangle AXYZ, what is the sinZ?159YZ121512O129Oc915Od1215e159 NPV calculstion) Calculate the NPV given the following free cash fiows, , if the appropriato roquired rate of return is 13 percent. Should the project be accepted? What is the project's NPV? (Round to the nearest cent.) Data table (Click on the following icon in order to copy its contents into a spreadsheet.) What are Doris' feelings? The maximum tension a 0.85 m string can withstand is 63.7 N. A 0.35 kg mass is attached to the string and is being whirled in a horizontal circle. What is the maximum speed of rotation?154.7 m/s12.4 m/s26.2 m/s5.1 m/s HELPPPPP ASAPPPP Determine which ordered pair is a solution to the equation: 2x - 5y = 9 Using the diagram above, identify the relationship between the mice and the wheat as it relates to the amount of available energy in each organism wls is preferred to ols when an important variable has been omitted from the model. true or false Find the exact value. How do I get to the answer of this question? a patient has blindness related to conversion (functional neurological) disorder but is unconcerned about this problem. which understanding should guide the nurse's planning for this patient? group of answer choices a. the patient is suppressing accurate feelings regarding the problem. b. the patient's anxiety is relieved through the physical symptom. c. the patient's optic nerve transmission has been impaired. d. the patient will not disclose genuine fears. Whats the opposite of - 7/10 express the number as a ratio of integers. 0.28 = 0.28282828 Mary ordered dinner for 10 people.Three people ordered the 4.75 chicken dinner, two people ordered the 4.95 fish dinner and five had beef dinner at cost of 6.75 each. What was the average cost of each dinner at Mary's party Help ASAP! Question 12 points)05.02 MCThe angles below are supplementary. What is the value of x? (5 points)57.51530 Help !!!!! Please need help Of the 200 graduate students who were interviewed for a par time position at a call center, 110 had a bicycle, 25 had a master card and 130 had a mobile phone. 50 of them had both, a bicycle and a master card, 30 had both, a master card and a mobile phone and 60 had both, a bicycle and mobile phone and 10 had all three. How many candidates had none of the three? The nurse is caring for a client who is taking a sustained-release (sr) oral nitrate. how should the nurse instruct this client to take the medication? If f(x) =|3x + 2, what is f(-1) how to track and trace requirements that have been identify and colected through the project's lifecycle to relate them to the project objectives Select the correct hybridization for the central atom based on the electron geometry COCl2 (carbon is the central atom).Select the correct hybridization for the central atom based on the electron geometry (carbon is the central atom).sp2sp3sp3dsp3d2