Question: Exercise 1 Assume s is a string of characters. Write a program that counts the number of vowels contained in the string s . Valid
Exercise
Assume s is a string of characters. Write a program that counts the number of vowels contained in the string s Valid vowels are both lower and uppercase: aeiouAEIO and U
For example, if s 'azcbobobegghAkl', your program should return
# GRADED CELL: def countVowelss: # Counts the number of vowels # input: string s of characters # output: number of vowels in s counter # counts the number of vowels ### START CODE HERE ### ### END CODE HERE ### return counter
# Quick Check s'azcbobobegghAkl' s'mdorJKLbnajwyrh$#&aaome s'hdgftygvetYqnjsvPOIciokjylyMYOAsvx' t countVowelss t countVowelss t countVowelss printOutput:ttt printExpected output: if ttt: printCongratulations all tests passed successfully!" else: printSorry try again!"
Exercise
Assume s is a string of characters. Write a program that outputs the number of times the string 'bob' in any combination of upper and lowercase letters ie 'bob', 'boB', 'bOb', 'bOB', 'Bob', 'BoB', 'BOb',and 'BOB' occurs in s
# GRADED CELL: def countBobs: # Counts the number of times 'bob' appears in s # input: string s # output: number of times 'bob' appears in s counter # counts the number of vowels ### START CODE HERE ### ### END CODE HERE ### return counter
# Quick Check s'azcbobobegghakl' s'mBOBOBOBmnddbvbobnshbohetg' s'bobmnfghbobOBbeyhrbbnbobob' t countBobs t countBobs t countBobs printOutput:ttt printExpected output: if ttt: printCongratulations all tests passed successfully!" else: printSorry try again!"
Exercise
Assume s is a string of lowercase letters. Write a program that outputs the longest substring of s in which the letters occur in alphabetical order. If two or more such substrings are possible, return the most left one.
Example: s 'abbampfxxaaa'. There are four longest substrings of s of length : 'abb', 'amp', fxx and 'aaa'. Your code should return 'abb'.
Note: Lowercase letters are alphabetically ordered in Python, ie a b c z
# GRADED CELL: def longestAlphSubStrs: # Returns the longest substring of s which is the in alphabetical order # input: string s composed of lowercase letters # output: longest substring of s which is the in alphabetical order longest s # stores the longest substring of s which is the in alphabetical order ### START CODE HERE ### ### END CODE HERE ### return longest
# Quick Check s'azcbobobegghakl' s'abbampfxxaaa' s'bobmnfghbobbeqqrtxzyhrbbnbobob' t longestAlphSubStrs t longestAlphSubStrs t longestAlphSubStrs printOutput: ttt printExpected output: 'beggh, 'abb, 'bbeqqrtxz' if tttbeggh'abb','bbeqqrtxz': printCongratulations all tests passed successfully!" else: printSorry try again!"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
