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
Ghella [55]
3 years ago
14

: Write a function "def countWords(string)" that returns a count of all words in an input string represented by the variable 'st

ring'.
Computers and Technology
1 answer:
Zina [86]3 years ago
3 0
We can define a word as a group of characters without a space between them. To find the words of the input string , w can use split(delimiter) which returns a list of strings which had the defined delimiter between them in the input string.

def countWords(string):
words = string.split(" ")
count = len(words)
return count

Here we set the delimiter as the space character, and returned the length of the words list. I split each step into its own line for readability, however the function could be one line:

return len(string.split())

Here, no delimiter is specified. If one isn't given, it will default to split at any whitespace, including space.

You might be interested in
Write a method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(l
kifflom [539]

Answer:

The java program for the given scenario is shown below.

import java.util.*;

import java.lang.*;

public class Test

{

   //variables to hold the number, digits and sum of the digits

   //variable to hold number is assigned any random value

   static long num=123;

   static int sum=0;

   static int digit;

   static int s;

   //method to add digits of a number

   public static int sumDigits(long n)

   { do

       {

           digit=(int) (n%10);

           sum=sum+digit;

           n=n/10;

       }while(n>0);

       return sum;

   }

public static void main(String[] args) {

    s = sumDigits(num);

 System.out.println("The sum of the digits of "+num+ " is "+s);  }

}

OUTPUT

The sum of the digits of 123 is 6

Explanation:

1. The variables to hold the number is declared as long and initialized.

2. The variables to store the digits of the number and the sum of the digits are declared as integer. The variable, sum, is initialized to 0.

3. The method, sumDigits(), is defined which takes a long parameter and returns an integer value. The method takes the number as a parameter and returns the sum of its digits.

4. Inside method, sumDigits(), inside the do-while loop, the sum of the digits of the parameter is computed.

5. Inside main(), the method, sumDigits(), is called. The integer value returned by this method is stored in another integer variable, s.

6. The sum of the digits is then displayed to the console.

7. All the variables are declared outside main() and at the class level and hence declared static. The method, sumDigits(), is also declared static since it is to be called inside main().

8. In java, the whole code is written inside a class since java is a purely object-oriented language.

9. In this program, object of the class is not created since only a single class is involved having main() method.

10. The program can be tested for any value of the variable, num.

11. The file is saved as Test.java, where Test is the name of the class having main() method.

7 0
3 years ago
A new drug to combat acne has been developed from a compound that is found in a melon. Which scientists would contribute to the
Ann [662]
The correct answer for this question is this one: "B. biologists and chemists."  A new drug to combat acne has been developed from a compound that is found in a melon. The <span>scientists would contribute to the development of the drug are biologists and chemists.
</span>
Here are the choices:
A. <span>chemists only
B. biologists and chemists
C. biologists, chemists, and physicists
D. biologists, chemists, and physicians</span>
8 0
3 years ago
Read 2 more answers
You have just performed a cpm analysis and have found that more than one path through the project network has zero slack values.
Alex787 [66]

Answer:

There are multiple critical paths

Explanation:

The critical path method (CPM), or critical path analysis (CPA), is an algorithm for scheduling a set of project activities. It is commonly used in conjunction with the program evaluation and review technique (PERT). A critical path is determined by identifying the longest stretch of dependent activities and measuring the time required to complete them from start to finish.

The essential technique for using CPM is to construct a model of the project that includes the following:

  •    A list of all activities required to complete the project (typically categorized within a work breakdown structure),
  •    The time (duration) that each activity will take to complete,
  •    The dependencies between the activities and,
  •    Logical end points such as milestones or deliverable items.      

Using these values, CPM calculates the longest path of planned activities to logical end points or to the end of the project, and the earliest and latest that each activity can start and finish without making the project longer. This process determines which activities are "critical" (i.e., on the longest path) and which have "total float" (i.e., can be delayed without making the project longer).

considering the above function of the cpm analysis because you have multiple path, there is tendency that more than path through the project network will have zero slack values.

5 0
3 years ago
Big Data _______________. Relies on the use of unstructured data imposes a structure on data when it is captured relies on the u
kifflom [539]

Answer:

captures data in whatever format it naturally exists

Explanation:

quizletBig Data _______________. Relies on the use of unstructured data imposes a structure on data when it is captured relies on the use of structured data captures data in whatever format it naturally exists

4 0
2 years ago
Which of these is not considered a final step when creating a Podcast? Getting a loan to help with the cost of the equipment. Ch
Neporo4naja [7]

Answer:

Option 1

Explanation:

Ok first off if your taking out a loan for your podcasting thats a issue. The other options are what you would normally do when setting it up because chances are you have the equipment necessary to start the podcast.

Hope this helps:)

6 0
2 years ago
Other questions:
  • In a transaction-processing system (TPS), if the TPS database can be queried and updated while the transaction is taking place,
    12·1 answer
  • Which of the following is the strongest password? Xo795&amp;A &amp;cGo9Tz F5h#3u9g vU7#$3T sC9$d&amp;cF5h#3u9g
    13·2 answers
  • What part of the code is a signal for the function to execute and pass back a value?
    11·2 answers
  • Effective presentations vary the color scheme on each slide.<br><br> True<br> False
    5·2 answers
  • One advantage of using a security management firm for security monitoring is that it has a high level of expertise.
    15·2 answers
  • linela Insurance needs to hire twenty accountants immediately to support its accounts receivable process. The hiring and trainin
    10·1 answer
  • What malware looks like a useful or desired executable program but is, in reality, a program that is supposed to cause harm to y
    11·1 answer
  • Open the NetBeans IDE and create a new project named MySizes.java. Your program should do the following:
    9·1 answer
  • True or False? Popular sites are always mean accurate.
    14·2 answers
  • Write a method to add/subtract two matrices. The header of the method is as follows:
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!