Question

Lab2: Processing Strings Part#1 – Counting Vows Assume s is a string of lower case characters....

Lab2: Processing Strings

Part#1 – Counting Vows

Assume s is a string of lower case characters.

Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should print:

Number of vowels: 5

Part#2 – Counting Bobs

Assume s is a string of lower case characters.

Write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then your program should print

Number of times bob occurs is: 2

Part#3 – Alphabetical Substrings

Assume s is a string of lower case characters.

Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl', then your program should print

Longest substring in alphabetical order is: beggh

In the case of ties, print the first substring. For example, if s = 'abcbcd', then your program should print

Longest substring in alphabetical order is: abc

Note: This problem is fairly challenging. We encourage you to work smart. If you've spent more than a few hours on this problem, we suggest that you stop. If you have time, come back to this problem after you've had a break and cleared your head.

USE PYTHON TO CODE THE PROGRAM!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part#1 – Counting Vows

vowels='aeiou'
s = input("Enter the string: ")

count=0
for ch in s:
if ch in vowels:
count+=1
print("Total number of vowels are:",count)

Jupyter Untitled1 Last Checkpoint: a few seconds ago (unsaved changes) File Edit Viewnr Cell Kenel Widgets Help In [1] vowels

Part#2 – Counting Bobs

word='bob'
s = input("Enter the string: ")

count=0
for i in range(len(s)):
if s[i:i+3] == word:
count+=1
print("Number of times bob occurs is:",count)

In [4] word-bob s input(Enter the string: ) count-0 for i in range(len(s)): if s[i:i+3] word: count+ 1 print(Total number

Part#3 – Alphabetical Substrings

def longest_substring(s):
groups = []
cur_longest = ''
prev_char = ''
for c in s.lower():
if prev_char and c < prev_char:
groups.append(cur_longest)
cur_longest = c
else:
cur_longest += c
prev_char = c
return max(groups, key=len) if groups else s

s=input("Enter the string: ")
sub_string=longest_substring (s)
print("Longest substring in alphabetical order is:",sub_string)

In [6]: def longest_substring(s): groups1 cur longest = .. prev_char for c in s.lower) if prev_char and c <prev_char: groups.

Add a comment
Know the answer?
Add Answer to:
Lab2: Processing Strings Part#1 – Counting Vows Assume s is a string of lower case characters....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Do in Python Problem 2 Assume s is a string of lower case characters. Write a...

    Do in Python Problem 2 Assume s is a string of lower case characters. Write a program that prints the number of times the string ' lol' occurs in s For example, if s= 'azclololegghakl', then your program should print S Number of times lol occu rs is: 2 Problem 3 Assume s is a string of lower case characters Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example,...

  • Write a C program to “de-vowel” an input string. Assume that the user provides input containing...

    Write a C program to “de-vowel” an input string. Assume that the user provides input containing only the characters a through z (i.e., all lowercase letters). Your program should create an output string that deletes all vowels from the input string, pushing the letters together to fill any gaps. For example, given the input “theturtleandthehare” your code should print out “thtrtlndthhr”. Your program should create an output string from the input string, before printing its output. Sample Input: Enter a...

  • You will be given several strings full of different keyboard characters, some of which are letters...

    You will be given several strings full of different keyboard characters, some of which are letters of the alphabet. Write a java program that creates a binary tree that uses only the alphabetical characters (a-z, A-Z) as the value within the leaf nodes using recursion and preorder traversal. All other values within the tree (either the root node or internal nodes) will be null. You may create any methods you see fit, so long as the final binary tree is...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two...

    Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two strings while ignoring the case of alphabetical characters. Your program will take two strings as input from the user and use your function to compare them. Assume a maximum C-string size of 1000 characters. Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Please properly comment your...

  • Question #2 A DNA molecule can be specified using a string of the characters , ‘g...

    Question #2 A DNA molecule can be specified using a string of the characters , ‘g 'a', 't'. Each of these characters represents one of the four nucleobases Cytosine, Guanine, Adenine, and Thymine. Consult the wikipedia page on DNA for more details. A codon consists of a sequence of three DNA nucle- obases and can be represented by a string of length 3 consisting of characters from the set ‘c', ‘g', ‘a", ‘t'. So "cga" and "ttg" are examples of...

  • C++ A Program for Examining String (1) Ask the customer to type any string they like...

    C++ A Program for Examining String (1) Ask the customer to type any string they like and then print it to the console. Example: Type a sentence: The CIS161 Computer Science II course is so much fun! You typed: The CIS161 Computer Science II course is so much fun! (2) Write the remaining code for the CountOfLetters() function, which returns the number of characters in the string that was entered. To get full credit for this question, this should be...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT