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
Which of these is not enumerated as a motivation to create accessible web content?
Gennadij [26K]

Answer:

Which of what?

Explanation:

7 0
2 years ago
In what real-life situations might you want to use the modulus operation in a program?
KonstantinChe [14]

Answer:

Since any even number divided by 2 has a remainder of 0, we can use modulo to determine the even-ess of a number. This can be used to make every other row in a table a certain color, for example.

5 0
2 years ago
With ____ editing, Word automatically displays a Paste Options button near the pasted or moved text.
harina [27]
The answer is drag and drop. 
 With drag and drop editing, word automatically displays a paste option button near the pasted or moved text. 
8 0
3 years ago
which of the following statements about servers is correct A. servers are computers on a network that share their resources with
givi [52]
A server can have many definitions, but in this particular case, the answer is A.  
7 0
3 years ago
Read 2 more answers
What is the decimal number 75 in binary and hexadecimal?
hammer [34]

Answer:

00110111 00110101-Binary

3735-Hex

8 0
3 years ago
Other questions:
  • The LTE (cellular telephone) standard supports only packet switching"". What cellular services are morst affected by this change
    15·1 answer
  • What does PHP stand for?
    9·2 answers
  • On the Insert tab, select Table &gt; _______ to create a table from selected text.
    14·1 answer
  • How read binary file in c++
    7·1 answer
  • What is the recommended secure protocol for voice and video applications? secure real-time transport protocol (srtp) hypertext t
    9·1 answer
  • What is the purpose of the domain name​
    5·1 answer
  • Which of the following is a sample IPv4 address?
    14·1 answer
  • Create a public class Dog that stores a single double age set by the constructor. (Reject negative ages using assert.) Dog shoul
    13·1 answer
  • 1)What is the hydropower resources/energy?
    7·1 answer
  • Which is the first computer brought in nepal for the census of 2028 B.S​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!