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)...
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 Programming Language is C++ Objective: The purpose of this project is to expose you to:...
The Programming Language is C++ Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student...
What is purpose of an objective tree and how it is developed ? provide the objective...
What is purpose of an objective tree and how it is developed ? provide the objective tree for a portable Wireless EEG (Electroencephalogram) device that can be used for medical and non-medical applications.
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX...
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX file system. Procedure: 1. OpenyourUnixshellandtrythesecommands: Ø Create a new file and add some text in it vcat > filename Ø View a file vcat /etc/passwd vmore /etc/passwd vmore filename Ø Copy file, making file2 vcp file1 file2 Ø Move/rename file1 as file2 vmv file1 file2 Ø Delete file1 as file2 vrm file //Deletefile //Double-checkfirst vrm -i file Ø Counts the lines, words, characters in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT