CPT 180 Chapter 8 (1st Edition) –
Chapter 9 (2nd Edition) Assignment 1
Directions
Using the following guidelines, create a python program.
1. Download the file CPT180Stuff.zip.
2. Extract this file into the root directory of one of your computer's drives. For example, you could
extract it on your C: drive or on to a USB drive such as E: drive. You should now have a folder
named CPT180Stuff located in your selected location. (If using a Mac, copy the downloaded zip
file to your documents folder. Extract the files here.)
3. Create a program named workWithFiles.py.
4. Add three comment lines at the top of the program that contain:
a. Program Name
. Program Description
c. Programmer's Name (You)
5. Write code that will do the following:
a. Print out the name of the cu
ent working directory.
. Change the cu
ent working directory to the CPT180Stuff folder.
c. Print out the name of the cu
ent working directory.
d. Create a new folder in the CPT180Stuff folder with the name "cellphones". In your code,
check and ensure that the folder does not already exist prior to attempting to create it.
e. Print out the contents of the CPT180Stuff folder as shown in Example Output.
f. Print out the contents of the CPT180Stuff\cars folder as shown in Example Output.
g. Print out the contents of the CPT180Stuff\pets folder as shown in Example Output.
h. Print out the contents and file sizes of the CPT180\pets\cats folder as shown in the Example
Output.
i. Print out the contents and file sizes of the CPT180\pets\dogs folder as shown in the
Example Output.
6. Submit the workWithFiles1.py file into the Chapter 8-9 Assignment 1 Submission Folder.
Example Output
CPT 180 Chapter 8 (1st Edition) –
Chapter 9 (2nd Edition) Assignment 2
Directions
Using the following guidelines, create a python program.
1. You will be using the CPT180Stuff folder from Assignment 1 for this assignment.
2. Create a program named workWithFiles2.py.
3. Add three comment lines at the top of the program that contain:
a. Program Name
. Program Description
c. Programmer's Name (You)
4. Write code that will do the following:
a. Using an if statement, determine if both the dognames.txt file and the catnames.txt file
exist. If both files exist, the program should complete steps b – m below. If either file does
not exist, the program should print out the message "Unable to access one or more files".
. Open the file named dognames.txt in the CPT180Stuff\pets\dogs folder in the read mode.
c. Print the contents of the file.
d. Close the file.
e. Open the file named catnames.txt in the CPT180Stuff\pets\cats folder in the read mode.
f. Print the contents of the file.
g. Close the file.
h. Open the catnames.txt file in the append mode.
i. Add two cat names to the file. You can pick the names. The example output below shows
the names Mortimer and Tigger added.
j. Close the file.
k. Open the catnames.txt file in read mode.
l. Print the contents of the file.
m. Close the file.
5. Submit the workWithFiles2.py file into the Chapter 8 - 9 Assignment 2 Submission Folder.
Hints
1. Ensure to add the newline character at the end of each name added to the file.
Example Output