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
zhannawk [14.2K]
4 years ago
11

2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you

to use a for loop in this function. (2 pts) (3) Extend the program by calling the get_num_of_characters() function and then output the returned result. (1 pt) (4) Extend the program further by implementing the output_without_whitespace() function. output_without_whitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the output_without_whitespace() function in main(). (2 pts)
Computers and Technology
1 answer:
Lilit [14]4 years ago
6 0

Explanation:

Number of characters: 46

String with no whitespace: Theonlythingwehavetofearisfearitself.

########################################################

def get_num_of_characters(inputStr):

   count = 0

   for i in range(0,len(inputStr)):

       count = count + 1

   #count = len(inputStr)

   return count

def output_without_whitespace(inputStr):

   #statement = statement.strip()

   statement2 = ' '

   for i in range(0,len(inputStr)):

        if(inputStr[i] == ' '):

           statement2 = statement2

       else:

           statement2 = statement2 + inputStr[i]

       

   inputStr = inputStr.replace(" ", "")

   return statement2

inputStr = input('Enter a sentence or phrase: ')

print()

print('You entered:', inputStr)

num = get_num_of_characters(inputStr)

print()

print('Number of characters:', num)

print('String with no whitespace:',output_without_whitespace(inputStr))

#if __name__ == '__main__':

   # Think I'm supposed to use this if statement

########################################################

'''ERROR MESSAGE WHEN RUNNING TEST

Unit test

0/1

Tests that get_num_of_characters() returns 46 for "The only thing we have to fear is fear itself."

Your output

Enter a sentence or phrase: Traceback (most recent call last):

 File "zyLabsUnitTestRunner.py", line 4, in <module>

   from zyLabsUnitTest import test_passed

 File "/home/runner/local/unit_test_student_code/zyLabsUnitTest.py", line 1, in <module>

   from main import get_num_of_characters

 File "/home/runner/local/unit_test_student_code/main.py", line 19, in <module>

   inputStr = input('Enter a sentence or phrase: ')

EOFError: EOF when reading a line'''

You might be interested in
Mobile devices typically come pre installed with standard apps like web browsers , media players, and mapping programs true or f
Step2247 [10]
This is true. New devices usually come with "stock" apps for the users convenience or to promote their own apps.
6 0
3 years ago
What are some of the opportunities that the stem program offers?
Vlada [557]

Science, technology, engineering, and mathematics (STEM) programs open the door to many different careers, including opportunities in engineering, science, and research. STEM professionals can explore diverse fields like aeronautics and biochemistry. Some STEM students also apply their technical knowledge in law, politics, and education.

Information obtained via: https://www.bestcolleges.com/careers/stem/

7 0
3 years ago
How can you make a search phrase more effective?
Whitepunk [10]

Let's solve this together.

To make a search term more accurate, you must keep it simple and you must be able to use more specific terms. The more specific you are with what you are asking the engine about, the more friendlier it will respond.

The answer is Option B. I hope this answer helped you!

4 0
3 years ago
Which data type is also called a binary object?
Andrej [43]
Binary large objects(BLOb):this data type is also called a binary object, and its fields are called binary fields.
7 0
3 years ago
Read 2 more answers
Meera has created a small program in Python. She wants to store elements of the same data type in an organized
blondinia [14]

Answer:

NumPy contains a large number of various mathematical operations.

...

Numpy | Mathematical Function.

Function Description

expm1() Calculate exp(x) – 1 for all elements in the array.

exp2() Calculate 2**p for all p in the input array.

log10() Return the base 10 logarithm of the input array, element-wise.

log2() Base-2 logarithm of x.

4 0
3 years ago
Other questions:
  • Which of the following jobs are most likely to be in greater demand due to the increasing prevalence of mobile computing? deskto
    13·1 answer
  • Your Economics teacher has asked you to create a chart showing how supply and demand affects the price of gasoline. Which applic
    13·2 answers
  • Which cloud computing service model will enable an application developer to develop, manage, and test their applications without
    15·1 answer
  • Give a recursive implementation for the function: def is_sorted(lst, low, high) This function is given a list of numbers, lst, a
    10·1 answer
  • What type of information is kept on a database?
    10·1 answer
  • Which of these is not a valid form<br>layout in Microsoft Access?​
    11·1 answer
  • I think my knee....
    14·1 answer
  • You designed a program to create a username using the first three letters from the first name and the first four letters of the
    6·1 answer
  • What is the plan to make optimum usage of available spaces?
    15·1 answer
  • Create a vector of structures experiments that stores information on subjects used in an experiment. Each struct has four fields
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!