Objectives
- Create an input loop to enter data
- Stop input when the user chooses to end it
- Validate user input
- Write data to a sequential access text file with each record being one line
This assignment involves the creation of a sequential access, variable-length record data file. You will create the user interface and store the data the user enters. Each record in the file must have the following format:
In addition, the string fields must have quotes(") added to the start and end, all fields must be separated by a comma, and there must be a newline added at the end of each record, like this:
"IT","V1001",1,3,2011,5.25
Your task is to present a nice user interface for the user that will loop until the user chooses to stop entering data. Each time the user completes the data entry for a record, write it out to a file named seqfile.txt. When you open the file, you should specify that you are appending data to the end. Remember that you will have to delete the seqfile.txt manually if you want to re-enter all the data for testing purposes since the program will always be appending to an existing file. You must follow the sample input and output formats exactly and include error checking. The error messages may have a different format than the sample as long as they are still understandable. All input should be converted to uppercase internally. The sample of what the contents of the file should look like when you enter the data from the sample run is shown at the end of this page.
# seqfile.txt erased # Python solution program run Enter dept ID: IT Employee ID: D4772 Enter month: 1 Enter day: 2 Enter year: 2011 Enter hours: 8.25 Enter another record? (Y/N) y Enter dept ID: IT Employee ID: F9642 Enter month: 1 Enter day: 4 Enter year: 2011 Enter hours: 8.25 Enter another record? (Y/N) n File seqfile.txt has been modified. # Python solution program run Enter dept ID: IT Employee ID: V1001 Enter month: -9 Integer value must be between 1 and 12, please re-enter: 1 Enter day: 34 Integer value must be between 1 and 31, please re-enter: 3 Enter year: 08 Integer value must be between 2000 and 2100, please re-enter: 2011 Enter hours: 480 Double value must be between 0.0 and 24.0, please re-enter: 5.25 Enter another record? (Y/N) p Error: Character entered is not a valid response. Enter another record? (Y/N) Y Enter dept ID: MGT Employee ID: A0010 Enter month: 1 Enter day: 2 Enter year: 2011 Enter hours: 6.5 Enter another record? (Y/N) N File seqfile.txt has been modified.
If you open the file you created in a text editor, you should see something like this:
"IT","D4772",1,2,2011,8.25 "IT","F9642",1,4,2011,8.25 "IT","V1001",1,3,2011,5.25 "MGT","A0010",1,2,2011,6.5