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
You are asked to provide a list of security groups a user is a member of. You write a script to pull the data from Active Direct
Whitepunk [10]

Answer:

I have no clue. I wish I could help though.

Explanation:

Sorry

7 0
3 years ago
Lael Masterson works in the Student Activities Office at Valerian State College in Illinois. Lael has started compiling informat
Nina [5.8K]

Answer:

Use the HLOOKUP function in the cell E2 by specifying the student's hourly rate value, the range of cells of the table holding the information, the row from which to return the value, and a value of true or false for approximate or exact match respectively.

Explanation:

Microsoft Excel is a statistics tool used for data analysis. It has several functions and graphical properties for cleaning and representing data.

The HLOOKUP function is an example of a search function in excel, it returns a value based on another value from a range of cells. The function accepts four arguments, they are, the value to be searched, the range table or cell range to search, the row to get the search value, and a mode of return value to return, could be either true for an approximate match or false for an exact match.

6 0
3 years ago
Why are duplicate tuples not allowed in a relation?
velikii [3]

Answer:

Explanation:

Duplicate tuples are not allowed in a relation because the specifications of the constraints of the regional integrity are violated, especially the main constraint that states that there can be no identical values for the attributes of two tuples at any database relation state.

Also, duplicate tuples are not allowed in a relation due to the fact that they lead to redundancy of the data base which in turn, slowing down the speed of the database when data processing such as inserting, querying, updating, deleting, etc are being performed.

4 0
3 years ago
The History feature of a browser enables you to retrace your browsing history over a short period of time. (1 point) True False
Elena-2011 [213]

The statement that the History feature of a browser helps in retracing browsing history over a short period of time is True.

<h3>What is a browser?</h3>

A browser can be regarded as an computer application that is used in surfing the internet.

One of the features of a browser is the history tab which helps to retrace your browsing history over a short period of time.

Learn more about browsers at;

brainly.com/question/24858866

6 0
2 years ago
You have installed a device that has eight interfaces and does not forward broadcast packets. What kind of device did you instal
Novay_Z [31]
A router, possibly. Thought I'm not for sure because I'm not in computers and technology

7 0
2 years ago
Read 2 more answers
Other questions:
  • In what decade did the Internet begin to be used widely by the public and not just government entities?
    5·2 answers
  • . A register in a computer has a of bits. How many unique combinations can be stored in the register?
    5·1 answer
  • &gt;&gt;&gt; import math &gt;&gt;&gt; print(math.Pi) 3.141592653589793 &gt;&gt;&gt; def print_volume(): print ("What is the radi
    12·1 answer
  • Consider the following code segment: ArrayList bulbs = new ArrayList(); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new L
    15·2 answers
  • You are late in the preparation of the computer graphics for your final report and presentation. You run into a friend who is gr
    13·1 answer
  • How many transponders are contained within a typical satellite?
    12·1 answer
  • Networking and telecommunications technologies, along with computer hardware, software, data management technology, and the peop
    5·1 answer
  • Implementing an interface means that you are adding to your class any mechanisms defined in an abstract class. Your class essent
    12·1 answer
  • What was that show where lowe’s were based off eye colors and the main character had orange eyes that let her mind control peopl
    14·2 answers
  • What are the differences between a cursor, insertion point and mouse pointer?​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!