Reread section 4.6 of the textbook on file processing.
Read Chapters 5 and 6. If you wish, you may skim sections 5.5-5.7, since we won't be delving too deeply into the details of graphics programming in this course.
Write a program called avgWordLen() that prompts the user for the name of a text file and reports the average word length of all words in the file to three decimal places. For example, using the text file haunting.txt, the output would look like this:
>>> avgWordLen() Enter file name: haunting.txt The average word length for haunting.txt is 5.048 characters >>>
Write a program called count() that prompts the user for the name of a text file and reports the total number of characters, words, and lines in the file. For example, using the text file haunting.txt, the output would look like this:
>>> count() Enter file name: haunting.txt haunting.txt contains 502 characters, 83 words, and 7 lines >>>
Write a program called copyfile() that prompts the user for the name of a text file and creates a copy of the file. The name of the new file should be the original name prefixed by "copy-of-". For example, to make a copy of the file haunting.txt, we would do this:
>>> copyfile() Enter file name: haunting.txt Made a new copy of haunting.txt called copy-of-haunting.txt >>>
The file elementsData.txt contains information about chemical elements. Each line corresponds to a single element, and consists of the following information:
Write a program called elements() that reads in the information from a file of this form and prints it out in a nicely-formatted table, exactly as shown below:
Element (symbol) Atomic Weight -------------------------------------- 1. Hydrogen (H) 1.008 2. Helium (He) 4.003 3. Lithium (Li) 6.939 4. Beryllium (Be) 9.012 5. Boron (B) 10.811 6. Carbon (C) 12.011 7. Nitrogen (N) 14.007 8. Oxygen (O) 15.999 9. Fluorine (F) 18.998 10. Neon (Ne) 20.183
Put all of your program definitions into a single file called assign4.py. Print out this file and turn it in to me in class on Wednesday. If you have questions about anything, don't hesitate to ask!