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
Misha Larkins [42]
3 years ago
9

In python, Write a function (name: identi Substring) that, given a string S, returns an integer that represents the numbers of w

ays in which we can select a non-empty substring of S where all of the characters of the substring are identical. Two substrings with the same letters but different in locations are still considered different. For example, the string "zzzyz" contains 8 such substrings. Four instances of "z", two of "zz", one of "zzz" and one instance of "y". String "k" contains only one such substring:"k". The length of S will be between 1 and 100, inclusive. Each character in S will be a lowercase letter (a-z).
Computers and Technology
1 answer:
svetoff [14.1K]3 years ago
7 0

Answer:

def identiSubstring(S):

    n = len(S)

    inst = ""

    count= 0

    for Len in range(1,n+1):

         for i in range(n-Len+1):

              for k in range(i,i + Len):

                   inst =inst+S[k]

              if(len(set(inst)) == 1):

                   count = count + 1

              inst = ""

    return count

           

S = input("Enter a string: ")

if(len(S)>=1 and len(S)<=100):

    print("There are "+str(identiSubstring(S.lower()))+" possible occurrences")

else:

   print("Length is invalid")

Explanation:

This line defines the required function

def identiSubstring(S):

This calculates the length of string S

    n = len(S)

This initializes an instance of the required string to an empty string

    inst = ""

This initializes count to 0

    count= 0

This following iterations iterate through the length of the string

<em>     for Len in range(1,n+1):</em>

<em>          for i in range(n-Len+1):</em>

<em>               for k in range(i,i + Len):</em>

This gets an instance of string S

                   inst =inst+S[k]

This checks if the characters of the instance are identical

              if(len(set(inst)) == 1):

If yes, the counter is incremented by 1

                   count = count + 1

This instance is reset back to an empty string

              inst = ""

This returns the number of instances of the substring

    return count

           

The main begins here

This prompt user for a string

S = input("Enter a string: ")

This checks for valid length

if(len(S)>=1 and len(S)<=100):

If length is between 1 and 100 (inclusive), this calls the identiSubstring function

    print("There are "+str(identiSubstring(S.lower()))+" possible occurrences")

If otherwise

else:

This prints invalid length

   print("Length is invalid")

<em>See attachment</em>

Download txt
You might be interested in
Why does 5 g mm wave require more cells to achieve a better signal
umka2103 [35]

Answer:

Higher frequencies have a shorter range.

7 0
3 years ago
You find information that you know to be classified on the internet. What should you do.
melomori [17]

A person is to find the information to be classified on the internet  are the best in the screenshot.

What is internet?

The word “internet” is also referred to as “net.” The global system of networks known as the Internet. Online services offered via the Internet include social media, email, and others. The without internet  are the not possible to share the information at the time.

A person is to find the information through which the internet is the best to justify. There used of the internet are the search the information with the help of the internet are the mic, keyboard. The information are the save and the screenshot was the used.

As a result, the person is to find the information to be classified on the internet  are the best in the screenshot.

Learn more about on internet, here:

brainly.com/question/13308791

#SPJ2

5 0
1 year ago
Read 2 more answers
Why do you think there is a difference between good, clean designs compared to the bad, cluttered designs below?.
Lemur [1.5K]

Answer:

Good, clean designs depicts the logic link of the company and easy to remember as compared to the bad, cluttered designs

Explanation:

The major difference between the good, clean designs and the bad, cluttered designs is that the good, clean designs depicts the logic link of the company and it is easy to remember such symbols but in case of bad, cluttered designs it is not that easy to find the logic link and also it is difficult to remember the logo.

7 0
3 years ago
Help it’s an exam brainleist
andreyandreev [35.5K]

Explanation:

Automatic transaction machine

False

True

8 0
3 years ago
One difference between setters and getters is: a setter has one or more parameters; a getter has no parameters.
tangare [24]
Boiiiiiiiii.
This is not a question
7 0
4 years ago
Other questions:
  • If a secret key is to be used as a _________ for conventional encryption a single number must be generated.
    13·1 answer
  • ________ are websites that provide collections of content from all over the world wide web a. aggregators b. social networks c.
    6·1 answer
  • FREE POINTS JUST ANSWER MY LATEST TWO QUESTIONS PLEASE
    10·2 answers
  • When evaluating portable CD players, you consider price, the sound quality, and ease of using the controls. These are your _____
    8·2 answers
  • Which of the following are examples of how a company might use consumer data it had collected? a To decide what types of product
    10·1 answer
  • Which of the following was (and still is) used by computer programmers as a first test program?
    13·2 answers
  • 1
    5·2 answers
  • Difference between a lesson plan and scheme of work​
    6·2 answers
  • I just logged onto brainly and all my questions were deleted and i lost 2 brainliest. What has brainly done to my account I also
    6·2 answers
  • From the introductory conversation chip and anna shared, which elements mentioned might suggest the use of case tools?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!