Posts

chapter 8 week 4 Assignment 8.5

Image
8.5  Open the file  mbox-short.txt  and read it line by line. When you find a line that starts with 'From ' like the following line: From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. Hint:  make sure not to include the lines that start with 'From:'. You can download the sample data at  http://www.py4e.com/code3/mbox-short.txt Answer:

chapter 8 week 4 Assignment 8.4

Image
8.4  Open the file  romeo.txt  and read it line by line. For each line, split the line into a list of words using the  split()  method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order. You can download the sample data at  http://www.py4e.com/code3/romeo.txt Answer:

chapter 8 week 4 quiz

chapter 8 week 4 quiz Index => chapter 8 week 4 quiz Quiz Show all questions <=   => How are "collection" variables different from normal variables? ?   Collection variables merge streams of output into a single stream ?   Collection variables can store multiple values in a single variable ?   Collection variables can only store a single value ?   Collection variables pull multiple network documents together What are the Python keywords used to construct a loop to iterate through a list? ?   try / except ?   def / return ?   foreach / in ?   for / in For the following list, how would you print out 'Sally'? friends = [ 'Joseph', 'Glenn', 'Sally' ] ?   print(friends[2]) ?   print(friends[2:1]) ?   print friends[3] ?   print(friends['Sally']) What would the followi...

chapter 7 week 3 Assignment 7.2

Image
7.2  Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution. You can download the sample data at  http://www.py4e.com/code3/mbox-short.txt  when you are testing below enter  mbox-short.txt  as the file name. Answer:

chapter 7 week 3 Assignment 7.1

Image
7.1  Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file  words.txt  to produce the output below. You can download the sample data at  http://www.py4e.com/code3/words.txt Answer:

chapter 7 week 3 quiz

chapter 7 week 3 quiz Index => chapter 7 week 3 quiz Quiz Show all questions <=   => Given the architecture and terminology we introduced in Chapter 1, where are files stored? ?   Main Memory ?   Central Processor ?   Motherboard ?   Secondary memory What is stored in a "file handle" that is returned from a successful open() call? ?   The handle contains the first 10 lines of a file ?   The handle has a list of all of the files in a particular folder on the hard drive ?   All the data from the file is read into memory and stored in the handle ?   The handle is a connection to the file's data What do we use the second parameter of the open() call to indicate? ?   Whether we want to read data from the file or write data to the file ?   How large we expect the file to be ?   ...