Question

In: Computer Science

Question Objective: The purpose of this lab is for you to become familiar with Python’s built-in...

Question

Objective:

The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str -- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents of another string object. String objects may also be added together (concatenation) and multiplied by an integer (replication). Strings may also be compared for “equality” and arranged into some order (e.g., alphabetical order, ordering by number of characters, etc.). Finally, strings may be placed in containers which can then be passed as arguments to functions for more complex manipulations.

Specifications:

Write an interactive Python program composed of several functions that manipulate strings in different ways. Your main() function prompts the user for a series of strings which are placed into a list container. The user should be able to input as many strings as they choose (i.e., a sentinel-controlled loop). Your main function will then pass this list of strings to a variety of functions for manipulation (see below).

The main logic of your program must be included within a loop that repeats until the user decides he/she does not want to continue processing lists of strings. The pseudo code for the body of your main() function might be something like this:

# Create the main function

def main():

# declare any necessary variable(s)

# // Loop: while the user wants to continue processing more lists of words

#

# // Loop: while the user want to enter more words (minimum of 8)

# // Prompt for, input and store a word (string) into a list # // Pass the list of words to following functions, and perform the manipulations

# // to produce and return a new, modified, copy of the list.

# // NOTE: None of the following functions can change the list parameter it

# // receives – the manipulated items must be returned as a new list.

#

# // SortByIncreasingLength(…)

# // SortByDecreasingLength(…)

# // SortByTheMostVowels(…)

# // SortByTheLeastVowels(…)

# // CapitalizeEveryOtherCharacter(…)

# // ReverseWordOrdering(…)

# // FoldWordsOnMiddleOfList(…)

# // Display the contents of the modified lists of words

#

# // Ask if the user wants to process another list of words

Deliverable(s):

Your deliverable should be a Word document with screenshots showing the sample code you have created, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them.

Submit the program you develop including captured output. Also turn in screen captures from running your program inputting, as a minimum, three (3) sets word lists (no fewer than 8 words per list).

Solutions

Expert Solution

def SortByIncreasingLength(word_list):
temp_word_list=[]
for word in word_list:temp_word_list.append(word)
return list(sorted(temp_word_list,key = lambda word:len(word),reverse=False))
def SortByDecreasingLength(word_list):
temp_word_list=[]
for word in word_list:temp_word_list.append(word)
return list(sorted(temp_word_list,key = lambda word:len(word),reverse=True))
def SortByTheMostVowels(word_list):
temp_word_list=[]
for word in word_list:temp_word_list.append(word)

return list(sorted(temp_word_list,key = lambda word:word.lower().count('a')+ \
word.lower().count('e')+word.lower().count('i')+word.lower().count('o')+word.lower().count('u'),reverse=True))

def SortByTheLeastVowels(word_list):
temp_word_list=[]
for word in word_list:temp_word_list.append(word)

return list(sorted(temp_word_list,key = lambda word:word.lower().count('a')+ \
word.lower().count('e')+word.lower().count('i')+word.lower().count('o')+word.lower().count('u'),reverse=False))

def CapitalizeEveryOtherCharacter(word_list):
temp_word_list = []
for word in word_list: temp_word_list.append(''.join([word[i].lower() if i%2==0 else word[i].upper() for i in range(len(word))]))
return temp_word_list

def ReverseWordOrdering(word_list):
temp_word_list = []
for word in word_list:
word=[l for l in word]
word.reverse()
temp_word_list.append(''.join(word))
return temp_word_list

def FoldWordsOnMiddleOfList(word_list):
# not clear as how this works
pass


def main():

while True:
word_list=[]
while True:
word=input('Enter a word (hit enter to stop): ')
if word=='':break
else:word_list.append(word)


print('Here are your words: ',word_list)
print('Sort By Increasing Length: ',SortByIncreasingLength(word_list))
print('Sort By Decreasing Length: ', SortByDecreasingLength(word_list))
print('Sort By Most Vowels : ', SortByTheMostVowels(word_list))
print('Sort By Least Vowels : ', SortByTheLeastVowels(word_list))
print('Capitalize Every Other Character: ',CapitalizeEveryOtherCharacter(word_list))
print('Reverse Word Ordering: ',ReverseWordOrdering(word_list))
print()
again=input('Do you want to process another list of words (yes or no)? ')
if again.lower()=='yes':continue
else:break

main()

out put:

enter a word (hit enter to stop): a

enter a word (hit enter to stop): e

enter a word (hit enter to stop): ae

enter a word (hit enter to stop): aei

enter a word (hit enter to stop): aeio

enter a word (hit enter to stop): aeiou

enter a word (hit enter to stop): fast

enter a word (hit enter to stop): furious

enter a word (hit enter to stop):

Here are your words:['a','e','ae','aei','aeio','aeiou','fast',,furious']

Sort by Increasing Lenght['a','e','ae','aei','aeio','fast','aeiou',furious']

Sort by decreasing Lenght['furious','aeiou','aeio','fast','aei','ae','a','e']

Sort by most vowels:['aeiou','aeio','furious','aei','ae','a','e','fast']

Sort by least values:['a','e','fast','ae','aei','aeio','furious','aeiou']

Capitalize Every other Character:['a','e','aE','aEi','aEio',aEiou','fAsT','fUrIoUs']

Reverse Word Ordering:['a','e','ea','iea','oiea','uoiea','tsaf','suoiruf']


Related Solutions

Purpose of Assignment The purpose of this assignment is to allow the students to become familiar...
Purpose of Assignment The purpose of this assignment is to allow the students to become familiar with and practice the measurement of Net Present Value (NPV), payback, and Weighted Average Cost of Capital (WACC) using Microsoft® Excel®. Assignment Steps Resources: Microsoft® Excel®, Capital Budgeting Decision Models Template Calculate the following problems using Microsoft® Excel®: Calculate the NPV for each project and determine which project should be accepted. Project A Project B Project C Project D Inital Outlay (105,000.000) (99,000.00) (110,000.00)...
The purpose of this lab:  Wireshark Intro Lab is to get students familiar with the use of...
The purpose of this lab:  Wireshark Intro Lab is to get students familiar with the use of their VMs and running wireshark on their VMs. We also examine Ethernet, IPv4, and TCP addressing at the Network Access, Network, and Transport layers of the TCP/IP stack. Reflection: In two paragraphs reflect the experience of using Wireshark capture (in the lab) on the following questions: What was the most valuable feature of the lab? How did you prepare for this lab? What changes...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
########################################################### # Lab 5 - Debugging # Name: # Date: # # Objective: # The purpose...
########################################################### # Lab 5 - Debugging # Name: # Date: # # Objective: # The purpose of this lab assignment is to help you understand # debugging processes in assembly language using debug tools # provided by QtSpim # # Description: # 1) Syntax, logic, and comment errors exist in: # - main # - print_array # - read_array # - allocate_array # 2) Find and fix the syntax, logical, and comment errors # *** Hint: Find all the "#To...
Co-occurring Treatment and Recovery Chart The purpose of this assignment is to become familiar with the...
Co-occurring Treatment and Recovery Chart The purpose of this assignment is to become familiar with the treatment and recovery methods, modalities, and strategies. After reading all assigned material complete the “Co-occurring Treatment and Recovery Chart” by filling in the information for the following categories below. Description or definition of the strategy: What is the strategy and modality? For example, regarding stages of change, what is the brief definition of this method? Key concepts and brief definitions: What are the common...
What is the objective, goal, abstract, and purpose of Inertial lab in physics report. And what...
What is the objective, goal, abstract, and purpose of Inertial lab in physics report. And what would be the conclusion.
The purpose of this question is to practice the pthread built in functions. The following c...
The purpose of this question is to practice the pthread built in functions. The following c program is a simple program to make a matrix of integers and print it. //File name: a.c #include <stdio.h> #include <time.h> #include <stdlib.h> int** a; int main(){ time_t t; int m, n, i, j;       //m is the numbers of rows and n is the number of columns. printf("Enter the number of rows, and columns: "); scanf("%d%d", &m, &n); printf("%d, %d\n", m, n); srand((unsigned) time(&t));...
You are required to become familiar with the workings of the Rat in a Maze program...
You are required to become familiar with the workings of the Rat in a Maze program and make certain adjustments to the program. To become familiar with the program I suggest that you run it several times, using a different maze and maybe a different food location. Also trace by hand to ensure you understand how each step works. The adjustments to be made are: 1. Allow the RAT to move in a diagonal direction, so now there are a...
The aim of this lab session is to make you familiar with implementing a linked list....
The aim of this lab session is to make you familiar with implementing a linked list. In this lab you will complete the partially implemented LinkedIntegerList. Specifically, you will implement the following methods. • public boolean remove(int value) • public int removeAt(int index) • public boolean set(int index, int value) • public int indexOf(int value) Task-1 Add a new class named Lab3Tester class to test the current implementation of the linked list. (Note: you may reuse the code from SimpleIntegerListTester...
Become familiar with the general basics of the regulatory rules applying to insider trading. You are...
Become familiar with the general basics of the regulatory rules applying to insider trading. You are not expected to become an expert in this topic. Apply this rule to the facts of this very brief case: Someone you know has knowledge of an impending merger between two companies. The combination of the two firms will certainly change the market dynamics of the industry and owners of stock in either company will greatly benefit, once the news of the merger is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT