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
You know that a candy bar costs sixty cents today. You also know the CPI for 1962 and the CPI for today. Which of the following
Elan Coil [88]

Answer:

d. sixty cents x (1962 CPI / today's CPI)

Explanation:

Dividing sixty cents with today's CPI and multiplying with 1962 's CPI would give the cost in 1962

7 0
4 years ago
How to make a website
hjlf

Answer:

You need an email and a job and to be over 18 for business ones or a legal gaurdian if you have none then ur hecced uwu :333

8 0
3 years ago
Read 2 more answers
What are the main dimensions of information systems
anastassius [24]

\huge\mathcal\colorbox{yellow}{{\color{blue}{AnSwEr~↓~↓~}}}

There are three dimensions of information systems

  • organizational
  • management
  • technology.

\huge \colorbox{blue}{hope \: it \: help \: u}

8 0
3 years ago
“Union-compatible” means that the ____.
Mnenie [13.5K]

Answer:

(c) will be the correct option

Explanation:

Union-compatible : If there are two relations and both have are having same number of attributes then it called union compatibility the domain of similar attributes also must be same for union compatibility. Number of attributes means number of column

so from above discussion it is clear that option (C) will be correct option

3 0
4 years ago
If there are three classes, Shape, Circle and Square, what is the most likely relationship among them?
xz_007 [3.2K]

Answer: B) Shape is a base class, and circle and square are derived classes of Shape.

Explanation:

Shape is a base class because circle and squares are the shapes so these are the derived class of the shape, which is inherited by the shape like circle and square. As, the base class (shape) is the class which are derived from the other classes like circle and square and it facilitates other class which can simplified the code re-usability that is inherited from the base class. Base class is also known as parent class and the super class.  

8 0
4 years ago
Other questions:
  • Consider an interface p ublic interface NumberFormatter { String format (in n); } Provide four classes that implement this inter
    15·1 answer
  • Write a complete program whose class name is hello and that displays hello, world on the screen.
    13·2 answers
  • Personal Area Network (PAN--
    10·1 answer
  • Your textbook discussed a record store example where one user could perform a query to determine which recordings had a track le
    14·1 answer
  • One microsleep warning sign occurs when you catch yourself leaning blank in the drivers seat
    12·1 answer
  • The if statement regards an expression with the value 0 as __________.
    13·1 answer
  • Declare a struct of your choice (Employee, Student etc). Delcare a node for singly link list. Declare an ADT of this linklist. T
    7·1 answer
  • What function does a resource manager in an IDE perform?
    14·1 answer
  • Use a for loop to output the numbers from 50 to 65
    6·1 answer
  • What’s unique about New Cashierless stores?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!