Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use python! Going for a run! To get started, write a function called run(string, Index) that takes as input a string and a number called
Use python!
Going for a run! To get started, write a function called run(string, Index) that takes as input a string and a number called index and returns the number of identical consecutive digits in the string beginning at position index. Whew, that's a mouthful; a few examples will help. run("11121,) Notice that index 0 we find the symbol "1" and there are three consecutive 1's before that "run" is broken by a dfferent symbol (a pesky 2). So, run returned 3 in this case. Here's another one: o run("11999913", 2) In this case, beginning at index 2 we have four consecutive 9's so the run has length 4 Your run function will use some sort of loop. It turns out that a while loop is a much better choice here than a for loop. Do you see why? A quick refresher on the anatomy of while loops. The general form is this while BLAH blah, blah, blah where BLAH is a Boolean expression; that is, something that is either True or False. Here are a few examples. This one starts with a variable x set to o. Then, while x is less than 10, we print x and try again. Eventually, x down and print "Hey, I finished!" increment it. Then, we try again. Eventually, x will become 10 and the loop ends. At that point, we drop Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started