Sale!

Lab Assignment 8 TCSS 142 solution

$30.00 $25.50

Category:

Description

5/5 - (1 vote)

OBJECTIVE

The objective of this assignment is to give you practice with lists, functions, and file reading.

ASSIGNMENT SUBMISSION

While the lab instructor walks around checking lecture exercises (pre-lab) on individual basis, start working with the partner of your choosing on exercise sets 2 and 3. Once you are done with a set, check with the one of the other pairs sitting next to you regarding their progress – help each other. Then, as a pair, present your solutions to the lab instructor. Each student is to have his version of the programs/answers and be capable of presenting them for the pair. The presenter will be chosen at random by the lab instructor. All the exercises other than the last set need to be shown to the lab instructor before leaving the lab for full credit. The last exercise set may be finished at home and is to be submitted via Canvas before the next lecture on Nov. 25. Use IDLE unless indicated otherwise.

Lecture Exercises (20%)

Show the following exercises you were to create during the lecture:
isAnagram.py
rainfall.py
earthStats.py

2. Basic Lists (25%)

Go to the website http://codingbat.com/python/List-2 and complete all List-2 exercises:
count_evens big_diff centered_average
sum13 sum67 has22

3. Lists and Functions (25%)

Answers to the following questions should be implemented as functions in a program called lists.py.
Write a function largerThan that takes a list alist and a number num as arguments and returns the new version of list consisting of all alist elements larger than num. For example, if a list containing the values [1, 2, 4, 2, 7] and a value 2 are passed to the function, it returns a list [4, 7].
Write a function called numDistinct that takes a single list parameter alist and returns a list containing distinct values in alist. For example, if a list containing the values [1, 2, 4, 2, 7] is passed to the program, it returns a list [1, 2, 4, 7].

You are not allowed to use a dictionary while solving this problem.
Write a function called normalizeList that takes a single list parameter and replaces all negative values in that list with zeros and all numbers greater than a hundred with a 100. All other values in range 0-100 are to remain intact. For example, if the list contains [ 0, 35, -23, 100, 200 ], then after the function executes, it should contain [ 0, 35, 0, 100, 100 ]. You are to assume that the list argument contains numbers only. Since all the changes you make to the list argument will be visible in the calling block, this function does NOT need to have the return statement.

4. Problem solving with lists, strings, functions, and files (30%)

Pig Latin is a language game of alterations played in English. To form the Pig Latin form of an English word:
if a word begins with a vowel, the ending way is added to the word, e.g. if becomes ifway
if a word begins with a consonant, the consonant is moved to the end of the word and the ending ay is added to the word, e.g. beast becomes eastbay

Write a program organized into functions that first reads a file containing words line by line from a text file called myPigLatinTest.txt. Assume that words are delimited by white spaces and that you only have valid words in this file.
When you read each line, convert it to a list of words using the method split.
Then, the program determines Pig Latin equivalents of the words in the list and prints them to an output file called PigLatinResults.txt.

For example, if the original file list contains:

if beast student
away

then the output file contains

ifway eastbay tudentsay
awayway

—– THE END —–

Lab Assignment 8 TCSS 142