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 the following statements is false?
Sedbober [7]

Answer:

The correct option to the following question is A.).

Explanation:

The following statement is false because,

  • We cannot use as the type-name throughout the function's body.
  • That's why the Wildcard type argument is referred to as the unknown types arguments and it acts as the placeholders for a real argument that are pass during the calling of the function.
  • A wildcard arguments are denoted by the Question mark(?).

7 0
3 years ago
THIS IS PYTHON QUESTION
frozen [14]

Answer:

ok

Explanation:yes

4 0
2 years ago
If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of s
olga55 [171]
I need more information
4 0
3 years ago
With dhcp, a device borrows, or ____ an ip address while it is attached to the network.
mestny [16]

I guess the correct answer is leases.

With DHCP, a device borrows, or leases an IP address while it is attached to the network.

8 0
3 years ago
A(n) _____ is created using the select and option elements that present users with a group of predefined possible values for the
aniked [119]

Answer:

c. selection list.

Explanation:

A selection list is created using the select and option elements that present users with a group of predefined possible values for the data field.

In Computer programming, the selection list is used to avail the end users with the ability to engage in an operation such as a predefined possible values for the data field.

7 0
3 years ago
Other questions:
  • &gt;
    6·1 answer
  • In what way(s) did the password you tried to use not meet the password policy requirements?
    14·1 answer
  • What is the role of programmers in an organization?
    6·1 answer
  • Which ipv6 prefix will the typical enterprise network receive from the service provider?
    12·1 answer
  • Amy just added a 462 meter run of fiber optic cable to the network what should she do next?
    10·1 answer
  • 50 POINTS &amp; A FOLLOW!
    11·2 answers
  • True / False<br> An instruction’s opcode generally indicates the number and type of its operands.
    5·1 answer
  • Which programming language was released first
    7·1 answer
  • When entering data in Access if the data is entered using an Access form, that data is stored in a table or tables. TRUE FALSE
    12·1 answer
  • What is the Role of an algorithm?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!