Write a program that reads a string and displays the longest substring of the given string having just the consonants.
Answers
Answered by
33
- string = input("Enter a string:")
- length = len(string)
- maxlength = 0
- maxsub ='' #empty string
- sub ='' #empty string
- lensub = 0
- for a in range(length):
- if string[a] in 'aeiou' or string[a] in 'AEIOU' :
- 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, "characters")
RudeGirl123:
Thanks a lot!!!
Answered by
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
Math,
7 months ago
Math,
7 months ago
Math,
7 months ago
Biology,
1 year ago
Computer Science,
1 year ago