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

Here is the grogram

def SortByIncreasingLength(wlist):
nlist = sorted(wlist, key=len)
return nlist

def SortByDecreasingLength(wlist):
nlist = sorted(wlist, key=len, reverse=True)
return nlist

def countVowels(s):
s1 = "aeiou"
count = 0
for c in s:
if c in s1:
count = count + 1
  
#print('in countvowel', s, count)
return count

def SortByTheMostVowels(wlist):
nlist = sorted(wlist, key=countVowels, reverse=True)
return nlist
  
def SortByTheLeastVowels(wlist):
nlist = sorted(wlist, key=countVowels)
return nlist

def CapitalizeEveryOtherCharacter(wlist):
new_wlist = []
for w in wlist:
str1 = ""
for i in range(len(w)):
if i%2 == 0:
str1 = str1 + w[i].lower()
else:
str1 = str1 + w[i].upper()
new_wlist.append(str1)
return new_wlist

def ReverseWordOrdering(wlist):
nlist = []
for i in range((len(wlist)-1), -1, -1):
nlist.append(wlist[i])
return nlist
  
def FoldWordsOnMiddleOfList(wlist):
return wlist


def main():
words = []
cnt = 0
while True:
aword = input("Enter minimum 8 words one ny one (quit to stop):")
if aword == "quit":
if cnt < 8:
print("You entered ", cnt, "words only. Enter more")
else:
break
words.append(aword)
cnt = cnt+1
#words =["sleep","cat","egg","little"]
  
while True:
print("1.Sort By Increasing Lenth of words")
print("2.Sort By Decreasing Lenth of words")
print("3.Sort By the most numnber of vowels")
print("4.Sort By the least numnber of vowels")
print("5.Capitalize every other character")
print("6.Revere word ordering")
print("7.Fold word on middle of list")
print("8.Exit")
ch = input("Enter your choice:")
if (ch == "1"):
print(words)
print("After Sort By increasing Lenth of words")
new_words = SortByIncreasingLength(words)
print(new_words)
if (ch == "2"):
print(words)
print("After Sort By decreasing Lenth of words")
new_words = SortByDecreasingLength(words)
print(new_words)
if (ch == "3"):
print(words)
print("After Sort By most number of vowels")
new_words = SortByTheMostVowels(words)
print(new_words)
if (ch == "4"):
print(words)
print("After Sort By least number of vowels")
new_words = SortByTheLeastVowels(words)
print(new_words)
if (ch == "5"):
new_words = CapitalizeEveryOtherCharacter(words)
print("After capitalizing every other character")
print(new_words)
if (ch == "6"):
print(words)
new_words = ReverseWordOrdering(words)
print("After reversing the ordering of words")
print(new_words)
if (ch == "7"):
new_words = FoldWordsOnMiddleOfList(list)
print("After folding words in middle of list")
print(new_words)
break
if (ch == "8"):
break

main()

code as image:

Output :


Related Solutions

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...
The purpose of this lab is to become familiar with searching, inserting and deleting elements in...
The purpose of this lab is to become familiar with searching, inserting and deleting elements in a linked list.using java   public boolean contains(String name) // returns true if provided name exists in the list, otherwise returns false public void add(String name) // adds name to the list in its proper lexographical (alphabetical) ordering public void delete(String name) // removes name from list
The purpose of this assignment is to have you become familiar with polymorphism and be able...
The purpose of this assignment is to have you become familiar with polymorphism and be able to design classes with inheritance The purpose of this assignment is to have you become familiar with polymorphism and be able to design classes with inheritance. Task The School Library has many items available for its students; some can be checked out and others cannot. Among those that can be checked out are journal (i.e., a literary journal) and digital video disk (i.e., a...
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)...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT