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
One item you will NOT need to provide when opening up a bank account
gladu [14]

Answer:

You don't need a birth certificate

Explanation:

8 0
3 years ago
Read 2 more answers
While you are working on your computer, it shuts down unexpectedly, and you detect a burning smell. When you remove the case cov
Virty [35]

Answer:

Replace the power supply

Explanation:

Usually, Capacitors burn up because of different factors.

- Exceeding operation voltage

- High Inverse voltage if is an electrolytic capacitor.

A tentative answer could be the battery, but usually the batteries damages are because wear out of them, that is, cycles of charging and discharging, a problem that could arise in the battery is related with the charge protection, this circuit cares that the battery only get the charge that it needs, in Li-po batteries is 3.7V, in some laptops is 24 V, if so the battery could explode or leaking acid.  

The mother-board is the "brain" and the Random Access Memory (RAM), they consume a lot of energy and usually heat up, but doesn’t produce increasing of voltage and its feed it by voltage regulators.

The only valid option is the power supply because the energy comes from a rectifier (made with diodes) and a voltage regulator that step-down the DC voltage output if by any chance the voltage increase or a diode burns up in the power supply the coupling capacitors or input capacitors in the computer will fail.

5 0
3 years ago
3.6 Code Practice on Edhesive
Alchen [17]

I've included my code in the picture below. Best of luck.

6 0
3 years ago
What’s your fave tv show?
kompoz [17]

Answer:

the vampire diareas

Explanation:

7 0
3 years ago
Read 2 more answers
HEYY GUYS START REPORTING ALL THE SPAMMERS PLSS!!!!! For the spammers, I hope you go to hell >:c!!!!!!!!!!!
Molodets [167]

Answer:

i totally agree

Explanation:

4 0
3 years ago
Other questions:
  • What is the other name of the horizontal column graph?
    6·2 answers
  • What is a computer??????????????????????????????????????????????????????????
    12·2 answers
  • Which of these symbols is a special character that is accessible only from the Symbol dialog box? A. © B. + C. é D.
    13·2 answers
  • What is the rationale behind the development of an operating system in computing?
    15·1 answer
  • David uses Office Excel 2013 to calculate his average marks. He enters a formula in cell B5 to calculate the average based on th
    11·1 answer
  • I make a budget of my 1st Gamer PC its good?
    9·1 answer
  • 1. Insert a Header that has the following in excel​
    14·1 answer
  • Nathaniel wanted to buy a microphone. He went to an electronics store and was told that there are actually two types of micropho
    13·2 answers
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • Write the importance of program in computer​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!