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
Y_Kistochka [10]
2 years ago
5

#We've started a recursive function below called #measure_string that should take in one string parameter, #myStr, and returns i

ts length. However, you may not use #Python's built-in len function. # #Finish our code. We are missing the base case and the #recursive call. # #HINT: Often when we have recursion involving strings, we #want to break down the string to be in its simplest form. #Think about how you could splice a string little by little. #Then think about what your base case might be - what is #the most basic, minimal string you can have in python? # #Hint 2: How can you establish the base case has been #reached without the len() function? #You may not use the built-in 'len()' function.

Computers and Technology
1 answer:
Roman55 [17]2 years ago
6 0

Answer:

Here is the Python program:  

def measure_string(myStr): #function that takes a string as parameter  

 if myStr == '': #if the string is empty (base case)  

      return 0  #return 0  

  else: #if string is not empty  

      return 1 + measure_string(myStr[0:-1]) #calls function recursively to find the length of the string (recursive case)  

#in order to check the working of the above function the following statement is used    

print(measure_string("13 characters")) #calls function and passes the string to it and print the output on the screen      

Explanation:

The function works as following:  

Suppose the string is 13 characters  

myStr = "13 characters"  

if myStr == '': this is the base case and this does not evaluate to true because myStr is not empty. This is basically the alternate of  

if len(myStr) == 0: but we are not supposed to use len function here so we use if myStr == '' instead.  

So the program control moves to the else part  

return 1 + measure_string(myStr[0:-1])  this statement is a recursive call to the function measure_string.  

myStr[0:-1] in the statement is a slice list that starts from the first character of the myStr string (at 0 index) to the last character of the string (-1 index)  

This statement can also be written as:  

return 1 + measure_string(myStr[1:])

or  

return 1 + measure_string(myStr[:-1])  This statement start from 1st character and ends at last character  

This statement keeps calling measure_string until the myStr is empty. The method gets each character using a slice and maintains a count by adding 1 each time this statement is returned.The function breaks string into its first character [0:] and all the rest characters [:-1]. and recursively counts the number of character occurrences and add 1. So there are 13 characters in the example string. So the output is:  

13

You might be interested in
A good way to assess your CPU usage is to:_______.
inna [77]
C is likely the best answer here.
8 0
3 years ago
Business intelligence is gained through industrial espionage and the gathering of this information often includes illegal or une
Nataly [62]

Answer:

A) True

Explanation:

Industrial espionage utilizes both illegal and unethical methods in gathering information about a corporate organization in order to get business intelligence. This involves stealing intellectual property and trade secrets to use them for a competitive advantage.  because Information about company's products, services, finances, sales, etc can be toold for  economic warfare

3 0
3 years ago
Everfi module 7 answers
Nat2105 [25]
What is the question?
7 0
2 years ago
What are the functions of information technology?
Gekata [30.6K]

There are six basic functions of IT.

1. Capture: Compiling detailed records of activities.

2. Processing: Converting, analyzing, computing and synthesizing all forms of data and information.

3. Generation: Organizing information into a useful form.

4. Storage: Retaining information for further use.

5. Retrieval: Locating and copying stored data or information for further processing or for transmission to another user.

6. Transmission: Distributing information over a communication network.

3 0
1 year ago
What do you need to do in order get paid for ads running on your content?
OverLord2011 [107]
If you're talking about YouTube or platforms like that, you have to monetize your videos in the settings. However, if your video contains copyrighted content, you will most likely be banned or given a strike for copyright infringement. You can monetize videos that have absolutely no copyrighted music, pictures or videos
4 0
3 years ago
Other questions:
  • In the database below, the arrow is pointing to a _____.<br> file<br> record<br> field<br> key field
    12·1 answer
  • Information systems security is the collection of activities that protect the information system and the data stored in it.
    12·1 answer
  • Write a program segment with a do-while loop that displays whether a user-entered integer is even or odd. The code should then a
    5·1 answer
  • If none of the contacts of a manual switch change status when the operator is activated, what is the most probable cause?
    9·1 answer
  • What is it called when two different files generate the same hashing result?
    15·1 answer
  • A lack of financial literacy can cause you to lose your
    10·1 answer
  • Does -8 = -21?<br>[this is NOT a trick question]<br>Yes....?<br>No!​
    12·2 answers
  • Taylor and Rory are hosting a party. They sent out invitations, and each one collected responses into dictionaries, with names o
    9·1 answer
  • A ___ is an online collaborative event that may include such features as chat, slideshows, and PowerPoint presentations.
    8·1 answer
  • Which of the following is an example of phishing attack? csp
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!