Computer Science, asked by RudeGirl123, 1 year ago

Write a program that reads a string and displays the longest substring of the given string having just the consonants.

Answers

Answered by AbhijithPrakash
33
  1. string = input("Enter a string:")
  2. length = len(string)
  3. maxlength = 0
  4. maxsub =''              #empty string
  5. sub =''                 #empty string
  6. lensub = 0
  7. for a in range(length):
  8.    if string[a] in 'aeiou' or string[a] in 'AEIOU' :
  9.        maxsub = sub
  10.        maxlength = lensub
  11.        sub = ''
  12.        lensub = 0
  13.    else :
  14.        sub += string[a]
  15.        lensub = len(sub)
  16.    a += 1
  17. print ("Maximum length consonant substring is :" , maxsub, end = ' ')
  18. print ("with", maxlength, "characters")

RudeGirl123: Thanks a lot!!!
AbhijithPrakash: Welcome :)
Answered by ankit1420
6

Answer:

string=input("enter a string :")

lenth=len(string)

length= 5

maxlength=0

maxsub=''

lensub=0

for a in range(length):

   if string[a] in 'aeiou'or string [a] in 'AEIOU':

       if lensub>maxlength:

           maxsub=sub

           maxlength=lensub

           sub=''

           lensub=0

   else:

       sub+=string[a]

       lensub=len(sub)

   a+=1

print('maximum length consonant substring is :',maxsub,end="")

print("with",maxlength ,"character")

Explanation:

Similar questions