In: Computer Science
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).
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']