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
Will mark Brainliest, need help ASAP!
Whitepunk [10]

Answer:

What Sherman needs to configure is:

RIPv2 class D of 240.

Explanation:

Multicast messages are usually dispatched to a select group of hosts on a network and require acknowledgement of the recipients. RIPv2 is a router-based internet protocol for exchanging routing information to the IP address 224.0. 0.9 on a network. It determine the most efficient way to route data on a network and to prevent routing loops.

3 0
2 years ago
Create a Produceclass that hasan instance variable of type Stringfor the name, appropriate constructors, appropriate accessor an
Nezavi [6.7K]

Answer:

you suck

Explanation:

5 0
3 years ago
. Why use a sensitivity analysis?
Natali [406]

Answer:

 Sensitivity analysis is the method in which it basically predict the final outcome of the decision. It analysis each variable individually and identify the dependency of the output value on the particular value of the input.  

The advantage of the sensitivity analysis is that it reduce the overall risk of the particular strategy and also impact of the system.

It basically work on the basic principle that firstly changed the structure and model and then observe the particular behavior of the model.

7 0
3 years ago
why is it important for young people to start saving early as possible given the principles of interest?
hjlf
<span>Saving at a young age could be a really great investment on your future from years from now. It has several benefits like learning how to handle your money properly, investing to grow your money more and an early retirement with a lot of coins in your pocket for when you want to enjoy traveling more.</span>
5 0
3 years ago
Read 2 more answers
Text box linking is for two or more text boxes in a document, when the text overflows from the first box. Which scenario is the
Julli [10]

Answer:

Explanation:

use the next box i think

8 0
3 years ago
Read 2 more answers
Other questions:
  • Send a document as a PDF when A. you want the recipient to make changes to the file. B. it needs to be printed. C. it contains m
    10·1 answer
  • Changing the user name in the word application is completed through the __.
    10·2 answers
  • You are using a crimper to attach an RJ-45 connector to a Cat 6 UTP cable. You need to use the T568A standard to connect the ind
    6·1 answer
  • What are the features of the Outline view in Word? Select three options.
    12·2 answers
  • PV = 11,000 AC = 6000 CV = 4,000. What is SV? What does this calculation tell you?
    6·1 answer
  • ______involves encoding information using fewer bits than the original representation Group of answer choices
    6·1 answer
  • A company has critical systems that are hosted on an end-of-life OS. To maintain operations and mitigate potential vulnerabiliti
    14·1 answer
  • ¿Qué ayuda nos proporcionan las herramientas tecnológicas en estos tiempo de pandemia? ayudaaaaa plis
    9·1 answer
  • What are the value and data type (float, int, bool, or str) of this expression:<br> 5 // 2
    9·1 answer
  • Imagine an everyday scenario in which you are using the internet: downloading a file, uploading a photo, checking your email, et
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!