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
How many parameters go into the function sum, and how many return values come out of the function sum? function sum(first, secon
zhannawk [14.2K]

Answer:

3 parameters are passed into the function.

1 value will be returned from the function.

Explanation:

From the function definition "function sum(first, second, third)", we can see  that there are three value/parameters are passed in the function.Then variable "result" will be the sum all the three values. After that it will print the all three values in new line. Then the function will return one value which is the  sum of all three that is value of "result".As there is only one value returned  by the return statement in the function.

6 0
3 years ago
Which device protects computer systems from voltage fluctuations?
meriva
A fuse protects computer system from voltage fluctuations
6 0
2 years ago
Read 2 more answers
What do we call exceptions to the exclusive rights of copyright law?
Studentka2010 [4]

Answer:

Fair use

Explanation:

I don't know if this is correct but Its the best option.

4 0
2 years ago
Assume the following variables are defined: int age; double pay; char section; write a single c instatement that will read input
JulsSmile [24]

Answer:

scanf("%d %lf %c", &age, &pay, &section);

Explanation:

To read the value in c program, the instruction scanf is used.

To read the integer value, use the %d format specifier in the scanf and corresponding variable name age with ampersand operator.

To read the double value, use the %lf format specifier in the scanf and corresponding variable name pay with ampersand operator.

To read the character value, use the %c format specifier in the scanf and corresponding variable name section with ampersand operator.

5 0
3 years ago
Sorts by value in reverse order; keeps the same key
KATRIN_1 [288]

Answer:

rsort()

Explanation:

the sorting function is used to sort the elements in the array.

the sorting can be increasing or decreasing, depends on the function used.

let discuss the option:

a. sort()

this is the sorting function, it used to sort the array in ascending order.

b. arsort()

this is also sorting function, it used to sort the associated array in descending order according to the value.

d. asort()

this is also sorting function, it used to sort the associated array in ascending order according to the value.

c. rsort()

this is the sorting function, it used to sort the array in descending order.

Therefore, the correct answer is rsort().

4 0
3 years ago
Other questions:
  • Which game would be classified as an educational game
    14·1 answer
  • What type of malware is heavily dependent on a user in order to spread?
    11·1 answer
  • How do I write code in Java for "A spinner for a game has four possible options: blue, red, yellow, green. The chance of landing
    10·1 answer
  • According to your​ reading, Macy's uses​ ________ technology to track individual items for sale on store shelves.
    5·2 answers
  • hello my friend is doing a give away at 100 followers would you follow him for a chance to win 2000 vbucks his name is ZoVa_Velo
    15·2 answers
  • An IT professional with a customer-service
    13·1 answer
  • 3.1.1 What type of goods are car radio and remote control.​
    12·1 answer
  • What is meant by the term text?
    14·2 answers
  • Because Brainly is such a big organization for students in need of help with their school work, I believe that it was either som
    15·1 answer
  • Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!