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
Should people who download music and movies illegally be punished?
Mrrafil [7]
Opinion wise, I disagree with punishment. 
3 0
3 years ago
What is it called when an attacker convinces you to enter personal information at an imposter website after receiving an email f
vodomira [7]

Answer:

Phishing.

Explanation:

Networks and computer systems in a network are susceptible to cyber attacks. A cyber attack is a networking term that describes a situation where a network is penetrated by a malicious process or program induced by an attacker or attackers.

A cyber attacker's sole intention is to steal information needed to achieve a malicious and devastating action to a client's personal assets. An example of such attacks is phishing.

Phishing is an attack that collects client's personal information at an imposter website after receiving an email from a person masquerading as an employee from a bank.

5 0
4 years ago
A seismograph has a heavy weight that is hung from a spring. What would happen if the weight were attached to a rod instead of a
Goshia [24]
<h2><u>Answer:</u></h2>

A seismograph has an overwhelming weight that is swung from a spring. As the spring is high touchy to the developments of the Earth at that point is the correct decision offer a seismograph.

On the off chance that this is changed by a pole, at that point it won't see the developments of the earth making the seismograph not precise and it would not work.

6 0
3 years ago
In this exercise, you will be given a phrase that includes the word “meat”. Replace that word with the word “fruit” and return t
Aleks [24]

Answer:

Answer is in the provided screenshot!

Explanation:

This answer is actually a simplified version of another question I've answered for you here: brainly.com/question/15538849

If you need any more explanation on how this algorithm works, please ask me!

8 0
3 years ago
Examine the evolution of the World Wide Web (WWW) in terms of the need for a general-purpose markup language. Provide your persp
creativ13 [48]

WWW is used to browse for view the webpage basically content is normally displayed as HTML pages.

In any browser's webpage irrespective of language been used output content display as HTML pages only.

<u>Explanation:</u>

  • In other methods is used XML format where it is opened and closed tag for every word editing XML file is very useful.
  • XML tools are ready is available where end-user can edit or create by for example notepad++ extra
  • It is a language designed to store the data in a specific format and easily process and used by a coding language or web pages.
4 0
3 years ago
Other questions:
  • Cover page styles in the cover page gallery match the preformatted styles in word, making it easier to create a coherent style b
    5·1 answer
  • In 2–4 sentences, describe how you would center text.
    11·1 answer
  • A relational database is different from a simple database because it has more than one _____.
    13·1 answer
  • A project manager types a document and prints it. He is using _____. hardware software hardware and software
    12·2 answers
  • What is the advantage of using a translation look-aside buffer (TLB), also called associative memory, in the logical-physical ad
    15·1 answer
  • The distance a vehicle travels can be calculated as follows: distance = speed * time For example, if the train travels 40 miles
    9·1 answer
  • Mi amiga es una chica y es soltera y quiere novia, a cualquiera le interesa?
    11·1 answer
  • Game Design!
    10·2 answers
  • Who made the game Monopoly???
    10·2 answers
  • Which things computer case contains
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!