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
hoa [83]
3 years ago
7

#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:
RideAnS [48]3 years ago
4 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 ________ displays a text box and button for users to browse, select, and upload a file. (Points : 3)
Vinil7 [7]
Upload text box control
6 0
3 years ago
Wright a 3 paragraph 5 sentences per graph story bout computers or the internet
boyakko [2]

Ah yes, technology.

Firsly, let's start at the begining. Because we can't have internet without computers. Think of it from the old quote, "Which came first? The chicken or the egg?"

Computers, or the very first programmable one was created by German Konrad Zuse. A man with too much free time, invented a computer in his parents' living room. And yes, it was considered  to be the very first electromechanical binary programmable PC. He called it the "Z1". There's actually no right answer to this to be quite frank, considering the many different classifications you'd call a computer back then.

Why was the computer invented? Why, where would we be without it? Certainly not here (hence brainly and you asking this question). Computers were created for the sole purpose of a repetitive calculation to perform more quick and accurately information.

5 0
3 years ago
A content team can create a custom board in Hootsuite Analytics with widgets displaying how their content is resonating with the
valkas [14]
<span>you might include things like total clicks, clicks by country, or reaction topics</span>
8 0
3 years ago
Read 2 more answers
Which of the following "masters" can be eamed without attending a collery or universites
SashulF [63]

Answer:

costume design

Explanation:

Ez

3 0
4 years ago
BRAINLIEST WILL BE GIVEN!!
Mnenie [13.5K]
Correct options are:

- You can insert rows and columns into, or delete rows and columns from, a spreadsheet.

- You can hide or show rows and columns in a spreadsheet.

- You can adjust the height of rows and width of columns.

Explanation:

You can insert rows and columns into, or delete rows and columns from, a spreadsheet.

Yes, you can easily add or delete rows and
columns from a spreadsheet.

You can hide or show rows and columns in a spreadsheet.

Yes, that is common to hide rows or columns to mask some data, then to unhide them.

You can adjust the height of rows and width of columns.

Yes, absolutely, you can also specify to wrap text that is too long to fit in the width of the cells.
7 0
3 years ago
Other questions:
  • Is a way of grading web pages by the number of other web pages that link to them?
    10·1 answer
  • There is an enormous amount of information on the Internet that is automatically separated into good content and not-so-good con
    15·1 answer
  • ________ is an encryption standard used for secure transactions such as credit card processing and online banking. TLS DMZ White
    14·1 answer
  • Useful open source applications include the popular Web browser Mozilla Firefox, the e-mail application Thunderbird, the relatio
    7·2 answers
  • Ian recently earned his security certification and has been offered a promotion to a position that requires him to analyze and d
    6·1 answer
  • How are XY coordinates utilized in construct ?
    15·1 answer
  • In order to send a photo in a text message from your cell phone to your cousin's cell phone who lives in New Zealand, is it nece
    8·1 answer
  • In what kind of attack can attackers make use of hundreds of thousands of computers under their control in an attack against a s
    7·2 answers
  • When a browser is open on your computer, what browser tool is used to move the webpage to the previously viewed page on the brow
    8·1 answer
  • Which option in PowerPoint allows users to configure the number of columns and rows manually, using numerical values?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!