1 answer

What would be the output of the following code? def get_letter_index(letter, string): returns the index of...

Question:

What would be the output of the following code? def get_letter_index(letter, string): returns the index of letter in string,

What would be the output of the following code? def get_letter_index(letter, string): returns the index of letter in string, OR if letter is not found in string, prints that information instead. If the letter occurs multiple times, this returns only the first index where the letter is found. Index where the letter is found for i in range(len(string)): if string[i] == letter: return i #if execution reaches this point, we must not have found the letter print(letter, "not found in", string) my_string = "alpha" p_index = get_letter_index("p", my_string) print(my_string[p_index])

Answers

If you have any doubts please comment below. Please give upvote if you like this.

Answer : p

there fore the output of following code is "p".

Explanation :

Instalize my_string with "alpha"
after we call the method get_letter_index() with arguments letter "p" and string my_str

Inside method :
   for loop itterates from i =0 to length of the given string
   check if i =0:
       string[0] == "p" false because string[0] is "a" so loop itterate
   check if i =1 :
       string[1] == "p" false because string[1] is "l" so loop itterate
   check if i =2 :
       string[2] == "p" true because string[2] is "p" so loop returns i i.e(i=2)

we assign that value to p_index i.e p_index = 2

finally we print the my_string[p_index] i.e the value of my_string[2] is "p"

.

Similar Solved Questions

1 answer
What is the expected major product resulting from the reaction of benzaldehyde with potassium permanganate? Select...
What is the expected major product resulting from the reaction of benzaldehyde with potassium permanganate? Select one: a. benzoic acid b. benzyl alcohol c. methylbenzene d. cyclohexanone e. no reaction...
1 answer
You are a researcher studying the lifespan of a certain species of bacteria. A preliminary sample...
You are a researcher studying the lifespan of a certain species of bacteria. A preliminary sample of 40 bacteria reveals a sample mean of z = 80 hours with a standard deviation of s = 4 hours. You would like to estimate the mean lifespan for this species of bacteria to within a margin of error of 0....
1 answer
Consider a transformation T: R2-R2 which acts by . first rotating the plane 30° counter-clockwise, then...
Consider a transformation T: R2-R2 which acts by . first rotating the plane 30° counter-clockwise, then stretching the plane vertically by a factor of 2, and contracting the plane horizontally by a factor of 1/2. -(1) and let e,- 0 Let eio Compute T(e) and T(e2), and give the matrix A with T(x) ...
1 answer
Questions #1: a) Describe normal urine. b) Identify factors that commonly influence urinary and bowel elimination....
Questions #1: a) Describe normal urine. b) Identify factors that commonly influence urinary and bowel elimination. c) For the following nursing actions during application of a condom catheter, state the underlying principles: i. roll the condom outward onto itself before putting on client. ii. inspe...
1 answer
Your body temperature can be taken by mouth, rectum, ear, or under your armpit. A reading...
Your body temperature can be taken by mouth, rectum, ear, or under your armpit. A reading considered to be of normal body temperature caries with the location of the reading. you are the nurse taking the temperature of a patient who, at a walk in clinic, complains of a persistent headache. Their tem...
1 answer
For a technical application, an electrical engineer needs to create a solenoid using copper wire with...
For a technical application, an electrical engineer needs to create a solenoid using copper wire with diameter d 0.500 mm. The resistance of the solenoid needs to be 3.500 and the magnetic field of the solenoid with a current of 2.50 A should be 6.50 x 10-T. Assume the resistance does not change sig...
1 answer
Exercise 10.16 0.4 m 30° 0.4 m A homogenous dise of mass 3 kg is welded...
Exercise 10.16 0.4 m 30° 0.4 m A homogenous dise of mass 3 kg is welded in the middle of a 0.8 kg/m uni- formn rol as shown in the figure. Deter- mine the angular acceleration a for the position shown when the rod is rotating atrad/s. Determine also components of the caction at A. R 0.1 m O= 2 r...
1 answer
What is #tan(theta/2)# in terms of trigonometric functions of a unit #theta#?
What is #tan(theta/2)# in terms of trigonometric functions of a unit #theta#?...
1 answer
QUESTION 4 a) Analyze the causes and consequences of the global financial crisis that started in...
QUESTION 4 a) Analyze the causes and consequences of the global financial crisis that started in 2007 b) What is neo-mercantilism? Explain how states attempt to protect their national interest in international trade through neo-mercantilist policies c) Is free trade possible? Discuss. Provide a crit...
1 answer
You nee to make 1 liter of a 2.00 M solution of glucose using anhydrous glucose...
you nee to make 1 liter of a 2.00 M solution of glucose using anhydrous glucose which has an assay value of 93.6% how many grams of glucose must you weigh out? (m.w. glucose is 180.000)...
1 answer
(4) Consider four charged particles fixed at the corners of a square with a side length...
(4) Consider four charged particles fixed at the corners of a square with a side length of 5 cm, see figure. The particles have charges q1--10 nC, q2 +10 nC, q3-20 nC, and q4 +10 nC. In unit vector notation, what net electric field do the particles produce at the square's center? q1 q2 q4 q3...
1 answer
A student bought $1000 worth of furniture. What is the equivalent annual cost at an intrest...
A student bought $1000 worth of furniture. What is the equivalent annual cost at an intrest rate of 5% and is expected to last 10years and can be sold for $200...
1 answer
Ferris Corporation Flow of Units and Equivalent Units Calculation, March 2019 Equivalents Units Where do the...
Ferris Corporation Flow of Units and Equivalent Units Calculation, March 2019 Equivalents Units Where do the units come from? Where do the units go? % Work Done? Direct Materials % Work Done? Conversion Costs Beginning Inventory Answer Completed/Transferred Answer Answer Answer Answer ...
1 answer
Case Study for Care Plan Assignment: fill each attached column with its appropriate answer, use the...
Case Study for Care Plan Assignment: fill each attached column with its appropriate answer, use the below scenario. A retired 69-year-old man "Mr. Casey" with a 5-year history of type 2 diabetes. Although he was diagnosed 5 years ago he had symptoms indicating hyperglycemia for 2 years befor...
1 answer
M A block with mass m, - 8.9 kg is on an incline with an angle...
m A block with mass m, - 8.9 kg is on an incline with an angle 8 - 24" with respect to the horizontal. For the first question there is no friction, but for the rest of this problem the coefficients of friction are: Pk - 0.23 and Ms - 0.253. 1) When there is no friction, what is the magnitude of ...
1 answer
An 8.000 gram sample of solid NH.NO, was mixed with a 200.00 mL sample of water...
An 8.000 gram sample of solid NH.NO, was mixed with a 200.00 mL sample of water in a coffee cup calorimeter. The water was initially at 20.0°C and the final temperature of the resulting solution was recorded as 17.1°C. Calculate the experimental AHcoln (in units of kJ/mol NH.NO:) for the dis...
1 answer
Extra Point (30 Points) Name ume that the economy is at full employment before the shift or in other words, st...
Extra Point (30 Points) Name ume that the economy is at full employment before the shift or in other words, start with the initial macroeconomic equilibrium. Basic Questions: Explain, using the graph with STATIC AD and AS model, what happens in the Short Run to AD, SRAS, the price level, the level o...
1 answer
A 6.0-volt battery is connected to a series in which the inductance is 0.25 henry and...
A 6.0-volt battery is connected to a series in which the inductance is 0.25 henry and the resistance is 5 ohms. Determine the current after 1 second if the initial current is 0. Round to 2 decimal places. Hint: Use the model Ldi/dt+Ri=E(t)...