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
how to answer the questions on brainly? I've typed my answer in the box but there's no submit button or whatever, and the only t
Zigmanuir [339]

Answer:

push the add your answer button

Explanation:

4 0
3 years ago
Read 2 more answers
List the equipment required to outfit a smaw station
Fudgin [204]

SMAW or Shielded metal arc wielding needs multiple equipments to be operational. Here is the list of equipments you need to start SMAW.

-          Constant Current (also known as CC) power supply for welding

-          Electrode holder

-          Lead

-          Ground Clamp

-          Welding electrodes

Additional equipment may also include the following:

-          Light shields

-          Jigs

-          Fixtures

-          Stool

-          Ventilation system

-          Workbench

 

You may refer to this link for more information:

 

https://books.google.com.ph/books?id=jNxCxwp2fHoC&pg=PA108&lpg=PA108&dq=smaw+station&source=bl&ots=aG_3eL4JN-&sig=TdFQP4wYjTSyG3z5-wv4tuuY0_g&hl=fil&sa=X&ved=0ahUKEwjuvtPI76zNAhWEn5QKHfowADcQ6AEISTAG#v=onepage&q=smaw%20station&f=false

 

<span> </span>

5 0
3 years ago
What is a device that is around the same size as a credit card, containing embedded technologies that can store information and
GarryVolchara [31]

Answer:

C. Smart card

Explanation:

Token: Token can be described as when something used to represent other i.e some kind of facts or quality.

Password: Password can be defined as a combination of secret words which used to login or gain access to anything.

Smart card: Smart card is of small-sized cards which contains some data and can process some tasks itself when used with a system.

Biometrics: Biometrics are mainly the fingerprints of anyone which is used for any purpose or as a password for something.

So the most appropriate answer is option C.

8 0
3 years ago
Which types of charts are examples found in Excel? Check all that apply.
marysya [2.9K]

Answer: 1,2,4,5,6

Explanation:

columns

bar

histogram

pie

scatterplot

5 0
3 years ago
Power point how to insert diamond symbol
IceJOKER [234]
You got to "insert" and then you go to "shapes" and then you find the symbol you like and you drag and drop it onto the page. Then you can resize to the size and angle you would like it at.
4 0
4 years ago
Other questions:
  • In JAVA, answer the following:
    15·1 answer
  • Terry came into work and turned on his computer. During the boot process, the computer shut down. When he tried again, the compu
    14·1 answer
  • George writes code for word processing applications. He is looking for a new job opportunity. What position should George look f
    5·2 answers
  • How do you create a logo on Adobe illustrator
    8·1 answer
  • 30 points!! What should I do if I plug my computer in and it starts making noises and sounds and it starts smelling.
    9·1 answer
  • What is a career pathway for ctso
    6·2 answers
  • _____ is a technique in which computers are designed with many microprocessors that work together, simultaneously, to solve prob
    15·1 answer
  • Convert the following denary numbers into binary using 8-bit register:
    6·1 answer
  • Win10如何删除自己添加的环境变量?...............
    8·1 answer
  • The following program calculates yearly and monthly salary given an hourly wage. The program assumes a work-hours-per-week of 40
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!