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]
3 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]3 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
the easiest and cheapest time to alter the information system is in the ________ phase of the sdlc. a. requirements analysis b.
nignag [31]
I would think its the "<span>requirements analysis" phase.

Because the </span>requirements analysis<span>,</span><span> is the process of determining user expectations for a new or modified product.</span>
7 0
4 years ago
Why can videos be streamed from the cloud to a computer with no loss in
mezya [45]
I think the answer is B
3 0
3 years ago
Read 2 more answers
A(n) _____ is a fake online persona created to promote a particular point of view, often in praise of a firm, product, or indivi
drek231 [11]

Answer:

<u>Sock puppet</u>

Explanation:

A sock puppet, a reference to a puppet created by placing a sock over one's hand, is a misleading or fake online identity created to promote a particular point of view, often in praise of a firm, organization, product, or individual; to manipulate public opinion or to argue, bully or review products. Regardless of the purpose it was created for, sock puppets are rarely welcome in online communities and forums.

4 0
3 years ago
To differentiate the absolute pathnames to files that are located on different drives, html requires you to include the drive le
Ber [7]
<span>To differentiate the absolute pathnames to files that are located on different drives, HTML requires you to include the drive letter followed by a </span>vertical bar.
4 0
3 years ago
What is the status of this account?
nydimaria [60]

Answer:

the answer is A my mom is a accountant and she pretty much told me everything she knows... lol

Explanation:

plz give brainliest and rating hope this helps^_^

5 0
3 years ago
Read 2 more answers
Other questions:
  • The term ________ refers to the use of a single unifying device that handles media, Internet, entertainment, and telephone needs
    7·1 answer
  • What is the height of the tallest possible red-black tree containing 31 values?
    7·1 answer
  • An essential skill today is knowing how to cite sources properly. Creative Commons has a system of licenses and tools for creato
    11·1 answer
  • Which of the following is an unintended consequence of pesticide use on crops?
    10·1 answer
  • Web sites use _____ to track users while they are on the site.
    14·1 answer
  • Computer virus is a<br> a. software<br> b. hardware<br> c. bacteria<br> d. none of these
    13·1 answer
  • HURRY UP !!!!!!’<br> Each packet is addressed to the recipient's .
    8·1 answer
  • Can some one help sorry I just so confused on this and I keep failing it I just need the help So choose the best answers
    12·1 answer
  • Although some families have more resources than other families, there is always a limited amount of resources that families have
    15·2 answers
  • Create a mobile app plan using PowerPoint slides to show mock-ups of screens,
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!