Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python You just finished administering the final exam for all of the stude

ID: 3767822 • Letter: U

Question

Using Python

You just finished administering the final exam for all of the students in the "Introduction to Computer Programming" classes this semester. The exam was a 25 question multiple choice exam, and it is your job to grade the exams. You have all of the scores stored in a series of text files.

To begin, download the data files and store them in a folder on your computer. Then create a new Python program inside of this folder. Make sure your source code file is inside of the same folder as the data files you just downloaded!

Next, write a program that lets the user type in the name of a file. Attempt to open the supplied file for read access. If the file exists you can print out a confirmation message. If the file doesn't exist you should tell the user that the file cannot be found and keep asking until the user enters a valid file name.

How to check whether a file exists There are two reasonably simple ways to check whether a file exists: Use Python's standard OS module Use a try/except block

We will not accept assignments that do not use one of these two techniques. Sample output

Here's a sample running of the program:

Enter a class file to grade (i.e. class1 for class1.txt): foobar

File cannot be found.

Enter a class file to grade (i.e. class1 for class1.txt): class1

Successfully opened class1.txt

Explanation / Answer

working python code for this check compiled on ideone.

I am using the os module way to check for the existence of the file. working code below:

import os.path
filename=raw_input("Please enter the file name in the current directory")
if os.path.isfile(filename):
   print "Successfully opened" + filename
else:
   print "File cannot be found"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote