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]
2 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]2 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
Louis is a civil engineer and wants to use a line on a floor plan that is indicative of the position from which a section is tak
frutty [35]

Answer:

A

Explanation:

horizontal line

8 0
2 years ago
Read 2 more answers
Without any formal planning, the president of a software company remarks in a speech that new technologically advanced software
Sphinxa [80]

Answer: The reducing project duration was caused by the emergence of new technology.

Explanation:

Emerging technologies are technologies whose development, practical applications, or both are still largely unrealized, such that they are figuratively emerging into prominence from a background of nonexistence or obscurity.

5 0
2 years ago
Match each of the following steps of SDLC development to its position in the development process.
Arisa [49]

Answer:

Step One - problem/opportunity identification  (V)

Step Two - Analysis (III)

Step Three - Design (II)

Step Four - Development (I)

Step Five - Testing and Installation (IV)

Explanation:

In the field of software development, or systems engineering, SDLC which refers to software development cycle refers to a systematic way of building software applications, it shows unique stages with the outcome of each stage dependent on the previous, step has a unique task which range from the planning, analysis, development, testing and installation of the information system.

5 0
3 years ago
Data files whose records are always retrieved in sequence from the beginning of the file are known as
dimaraw [331]

Answer:

sequential files

Explanation:

Q:

Data files whose records are always retrieved in sequence from the beginning of the file are

A:

sequential files

3 0
2 years ago
What is a limitation of the flash memory card select one of the options below as your answer:
Inga [223]
The answer is C. You can only use it with the correct memory card reader.
4 0
3 years ago
Other questions:
  • Write a while statement that prints all even numbers between 1 and 100 to the screen.
    6·1 answer
  • Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
    9·2 answers
  • You're setting up some VMs to test an application you're considering making available to employees of the small company you work
    11·1 answer
  • Which technique will NOT help you build rapport with your colleagues?
    15·1 answer
  • How are satellite radio, Internet radio, and podcasting different?
    11·1 answer
  • Give me at least five main characteristic of irrigation equipment​
    8·1 answer
  • Which line of code will find the first occurrence of a three in an array?
    5·2 answers
  • What is smarta Art ? ​
    10·1 answer
  • Pa answer po thank you​
    7·2 answers
  • 90 POINTS Hazel is working with a database to help determine if the company she works for is making or losing money. Hazel has o
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!