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,...

  • In this part of the assignment, you will write MIPS assembly code to replace characters in...

    In this part of the assignment, you will write MIPS assembly code to replace characters in a string. This program asks the user for a string named string and two characters orig and new. It then replaces each instance of the character orig found in string with the character new. It outputs the resulting string and the number of substitutions that were made. For example, if string were "wow", orig were 'w', and new were 'b', the program would output...

  • C++ 10.4 String to number Write a program that 1.reads in 4 upper case characters Converts...

    C++ 10.4 String to number Write a program that 1.reads in 4 upper case characters Converts each into its Ascii equivalent integer 3.Adds all these numbers together Converts this resulting integer to a string Prints the string. Divides the integer result by 4 Converts this back to an Ascii char prints the char

  • 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...

  • 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...

  • 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...

  • Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that...

    Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that occurs as consecutive characters (not just letters, but any characters) in s. so longestSubpalindrome("ab-4-be!!!") returns "b-4-b".If there is a tie, return the lexicographically larger value -- in Python, a string s1 is lexicographically greater than a string s2 if (s1 > s2). So: longestSubpalindrome("abcbce") returns "cbc", since ("cbc" > "bcb"). Note that unlike the previous functions, this function is case-sensitive (so "A" is not...

  • Part 1. Write a program that takes a string as input, strips whitespace and punctuation from...

    Part 1. Write a program that takes a string as input, strips whitespace and punctuation from the words, and converts them to lowercase. Hint: The string module provides strings named whitespace, which contains space, tab, newline, etc., and punctuation which contains the punctuation characters. Let’s see if we can make Python swear: >>> import string >>> print string.punctuation !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ Also, you might consider using the string methods strip, replace and translate (Chapter 2 of "Introducing Python" is a great reference...

  • Write the code in python programming Language String Statistics: Write a program that reads a string...

    Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...

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