Lab 7 v1
Lab 7 v1
IS111 Lab 7
Instructions:
Suggest that you create a working folder is111\lab7 in your C or D drive. Store all your solutions in this
working folder.
Challenging questions are marked with *.
To submit:
Please submit your working solutions via your assignment Dropbox in eLearn within 1 week. The Dropbox
will be closed after the due date.
- Zip up all your source files into a single zip file called <your email ID>_lab7.zip (e.g.
ahlian.lim.2011_lab7.zip). You should only submit a single zip file for each lab.
1. [*] In a file named lab7_1.py, write a program to read from the file called words.txt. Every line in words.txt
contains one single word. The program is supposed to read words in the file and print all words along with
the count of distinct vowels present in the word as shown in the sample run. You may want to write
additional functions in the file, one function perhaps to count the number of distinct vowels in every word
etc.
Here is the output when lab7_1 is run (with the given test words.txt file):
D:\is111\lab7>python lab7_1.py
python 1
dynamic-typed 3
function 3
parameter 2
argument 3
str 0
int 1
float 2
To submit: lab7_1.py
2. [**] In a file named lab7_2.py, write a program that reads inputs from a file called phone.txt. Every line
in phone.txt contains one phone number. The program is supposed to verify if lines in the text file contain
valid phone numbers and write out only valid phone numbers one number in a line into a file named
valid.txt
A valid phone number has the format
Nddd-dddd where N is 6 or 8 or 9 and d is any digit 0-9
Here is the output when lab7_2 is run (with the given phone.txt file):
D:\is111\lab7>python lab7_2.py
Invalid phone numbers:
7346-8895
123445384
846-7894
6457-q088
To submit: lab7_2.py
IS111- Lab7 1
SMU Classification: Restricted
IS111 Lab 7
3. [*] In a file named lab7_3.py, write a program that reads inputs from a file called sales.txt. Every line in
sales.txt contains sales amount of a particular month in the format.
Month name, Sales amount
Your program is supposed to print the total sales amount of all months in the file on the screen.
Here is the output when lab7_3 is run (with the given phone.txt file):
D:\is111\lab7>python lab7_3.py
Total sales amount for the whole year $64481.90
To submit: lab7_3.py
4. [***] There is a belief that humans are able to read even when the order of the letters are misplaced. Try
reading this:
I cnduo't bvleiee taht I culod uesdtannrd waht I was rdnaieg
In a file named lab7_4.py, write a program that reads text from a file called talk.txt and prints the
content on the output screen scrambling the words in the content as described below:
Scramble every word in the text leaving untouched the first and last letter
You may assume that the text has words separated by a single space. Maintain single space
between words in the scrambled version
Challenge yourself to omit the punctuations [, ' ! .] in the content untouched in the original place
(Adapted from the book The practice of Computing using Python - Programming Project on Page 340)
As you think of designing solution for this question, define and make use of functions to do simpler tasks.
Test the function before building on to complete the solution.
Note: To scramble middle letters of a 6-lettered word, you could take each letter in the indices 1-4 and put
them in positions randomly between 1 and 4. A 6-letter word after scrambling should contain all the six
letters.
To make this exercise simpler, if after scrambling one word if output happens to remain the same as the
original, you may ignore.
You may want to use random module to help you with scrambling letters.
To submit: lab7_4.py
IS111- Lab7 2