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]
3 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]3 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
ANWSER ASAP
Alona [7]

Answer:

Cell wall more selectively controls what goes in and out of the cell, it gives a plant cell its shape, is rigid.

6 0
2 years ago
File explorer provides ____ ways to view the contents of a folder.
AURORKA [14]
2 or 3 ways.......................................
5 0
3 years ago
At what two layers of the osi model are lan and wan protocols likely to differ??
Anuta_ua [19.1K]
A LAN is connecting two or more computers to form a cable network between them.
<span>A WAN is connecting two or more computers over a broad area to form a cable network between them.</span>
5 0
3 years ago
) The _____ method of a radio button returns true if that button is on.
Lostsunrise [7]

Answer:

isSelected()

Explanation:

The isSelected() method of a radio button returns true if that button is on and false otherwise. This method is defined in the class javax.swing.AbstractButton. JRadioButton class inherits from AbstractButton and thus has access to this method. An application code can invoke this method on the radio button instance to determine th ecurrent state and alter the control flow accordingly.

4 0
2 years ago
A credit given to an author for his or her work is called a(an)
Bad White [126]

Citation.

Any other related questions you want answered?

5 0
2 years ago
Other questions:
  • Unix has experimented with several security programs. a user can attach a watchdog program to a file that grants or denies acces
    13·1 answer
  • Tracy has a file that contains a list of actors and the movies in which they acted. She wants to know the top 3 ranked actors fr
    10·1 answer
  • ) Consider a router that interconnects four subnets: Subnet 1, Subnet 2, Subnet 3 and Subnet 4. Suppose all of the interfaces in
    11·1 answer
  • Do you need to know javascript to learn python?
    8·1 answer
  • What do you believe are the motives of a cyber criminal? Why?
    15·1 answer
  • Write the printItem() method for the base class. Sample output for below program:
    8·1 answer
  • What name is used to denote a common field that exists between two tables, but is also the primary key for one of the tables??"
    8·1 answer
  • What are the two ways to print a document?
    11·1 answer
  • What are search tries? Why are they more efficient than usualsearching<br><br> algorithms?
    8·1 answer
  • What is SoC? how is it different from CPU?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!