CS 1101 – Programming Fundamentals

Description

Introduction

Don't use plagiarized sources. Get Your Custom Assignment on
CS 1101 – Programming Fundamentals
From as Little as $13/Page

Welcome to unit 8!

Unit 8 introduces reading and writing text files in Python. In particular, you will learn how to read the lines of a text file using a for loop and how to write lines one at a time. To help with writing, the unit describes an important new use of the “%” operator to format text output. You will also learn how to find files on a computer and put new files where you want them, using functions from the os and os.path modules. These functions navigate the file system’s directories (also known as “folders”).

Finally, the unit covers how to handle file errors by catching exceptions. You will learn about try blocks, which allow you to call functions that might raise exceptions and “catch” those exceptions to deal with the problem. Our final unit is complete, and I sincerely hope you learned a lot and enjoyed the course.

Finally, I want to wish you luck on your Final Exam for CS 1101!

ATTRIBUTION

“Python Program” by thekirbster is licensed under CC BY 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by/2.0/?ref=openverse.

Reading Assignment

Reading Assignments are designed to expand your knowledge of the topics introduced in the Overview and provide the knowledge you will need to successfully complete the assignments in this unit. As you read through the learning resource and watch the videos consider the following:

How are file errors addressed with exception handling?
What is the process of reading and writing to a file?
READ
Think Python: How to think like a computer scientist
Chapter 9 – Case study: word play, Section 1
Chapter 14 – Files, Sections 1-5
WATCH: PYTHON TUTORIAL: FILE OBJECTS – READING AND WRITING TO FILES

SUPPLEMENTAL READING
Think Python: How to think like a computer scientist
Chapter 14 – Files, remaining sections
REFERENCES
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf

Schafer, C. (2016, April 29). Python tutorial: File objects – Reading and writing to files [Video]. YouTube.
Discussion Assignment

Welcome to the Unit 8 Discussion Forum and your final discussion prompt for this course.

PART 1

Describe how catching exceptions can help with file errors. Write a Python example that implements exception handling for any one of the file errors. Your code should use, try: except: blocks. Clearly mention the exception name in except block that you would handle. Include the code and output in your post along with necessary explanation.

PART 2

Describe how you might deal with a file error if you were writing a large production program. These descriptions should be general ideas in English, not actual Python code.

The code and its output must be explained technically whenever asked. The explanation can be provided before or after the code, or in the form of code comments within the code. For any descriptive type question, Your answer must be at least 150 words.

Remember to post your initial response as early as possible, preferably by Sunday evening, to allow time for you and your classmates to have a discussion.

When you use information from a learning resource, such as a textbook, be sure to credit your source and include the URL. Continue to practice using APA format for citations and references.

Programming Assignment

Assignment Instructions:

This assignment is assessing your skills and knowledge on applying Python programs that convert lines of text into dictionaries and convert dictionaries into lines of text and utilizing exception handling to deal with Python file errors.

In this unit, we have explored the basic concepts of Files. Before you proceed with this assignment, please review the reading material listed below:

Think Python: How to think like a computer scientist,
Chapter 14 – Files,
Section 14.1 – Persistence to Section 14.5 – Catching exceptions
Watch: Python Tutorial: File Objects – Reading and Writing to Files. https://youtu.be/Uh2ebFW8OYM

Write a program to read dictionary items from a file and then write the inverted dictionary to a file. Ensure the program includes the following components:

1.The input file for your original dictionary (with at least six items).

2. The Python program you used to read from a file, invert the dictionary, and write to a different file. (You need to create a dictionary file and invert it into another file).

3. The output file for your inverted dictionary.

4. Provide a technical explanation for the code and its output in a minimum of 200 words.

Sample Input File (Not specific)

{

apple: red

banana: yellow

cherry: red

mango: yellow

grapes: black, green

}

Sample Output File:

{

red: apple, cherry

yellow: banana, mango

black: grapes

blue: grapes

}

PROGRAMMING INSTRUCTIONS:
The code and its output must be explained technically. The explanation can be provided before or after the code, or in the form of comments within the code.
SUBMISSION INSTRUCTIONS:
Submit the solution in a word document.
Make sure your submission is double-spaced, using Times New Roman, 12-point font, with 1” margins.
Use sources to support your arguments. Add a reference list at the end of the submission. For assistance with APA formatting, view the Learning Resource Center: Academic Writing.
Your submission should be clearly written, concise, and well organized, and free of spelling and grammar errors. Read the grading rubric to understand on how your work will be evaluated

References:

Downey, A. (2015). Think Python: How to think like a computer scientist (2nd ed.). Green Tea Press.
Schafer, C. (2016, April 29). Python tutorial: file objects – Reading and writing to files [Video]. YouTube. https://youtu.be/Uh2ebFW8OYM
Python File Open. (n.d.). W3schools.

This assignment will be assessed by your instructor using the rubric available on the assignment page located on the course homepage.