For this assignment, you will be reading text data from a file, counting a number of words, and writing the results to a new file. The details of how your program should work are described in the Requirements section below.
Input Data: A sample input data file (hobbies.txt) that your program should process is distributed together. This sample file contains descriptions of the hobbies of 26 students. However, your program should be able to work with a file with an arbitrary number of students. For example, I may test your program with just 3 students or with 300. Your program should work for any length file.
Each student record spans 3 lines in the data file. The first line contains the ID of the student (e.g., student_1, student_2, and student_3). I anonymized the student id. The second line contains a description of the student’s hobby. The third line contains the pre-counted number of words of the hobby description. Your program will need to count the number of words in the hobby description, compare your count with the pre-counted number, and decide whether the pre-counted number is correct or not.
For instance, the following sentence has 9 words.
“Camping with my family is one of my hobbies.”
Camping, with, my, family, is, one, of, my, hobbies are all words that will be counted.
Output Data: Your program should write the results of its computations to an output file. An example of the required output file (5_sample_count_output.txt) is distributed together. This sample file contains mock-up data for 5 students. You are supposed to process all 26 students’ hobbies in the actual assignment. This sample output is just for demonstration. Each student record spans 3 lines in the data file. The first line contains the student ID. The second line contains the count of words by your program. The third line contains the evaluation of whether the pre-counted number of words is correct or not (e.g., True or False).
Requirement
Your program should perform the following:
- Prompt the user to enter the name of the input file, making sure that the file exists and asking the user to re-enter a filename if needed.
- Prompt the user to enter the name of an output file. The output file should be erased/overwritten if an old one with the same name exists.
- Read the input file, evaluate whether the pre-counted number of words is correct for the student (True vs. False), and write the output to the file. You also should include student ID and word count.
When you count the number of words, you can use the built-in split() function. For instance, if text is a variable that stores string, you can use split() function as follows: text.split(). The split() function will return a list of words. This method might not return a perfect word list. For instance, it can return “movie.” which includes a period, or “hobbies/interests” which includes a slash between two words. Separating words accurately is not the goal of this assignment. Instead, we want to practice reading and writing a file and to get a sense of text processing. Those incompletely separated words will be counted just as one. In other words, you need to consider “hobbies/interests” to be one word. For splitting words, you just need to depend on the functionality of the split() function. You learned how to count the number of elements in the list during the class. You can use len() function. I changed three pre-counts to the wrong numbers. Thus, if you find three wrong word counts, your program is probably working well. It’s just a clue, though.
Two kinds of output should be produced by your program. First, an output data file should be created using the same format described in the "Output Data" paragraph of the Overview section above. Second, your program will produce output on the console in the form of status messages and prompts for user input. The output produced by your program should be nearly identical to the sample output provided below. While the specific data (student_ID, word count, etc.) will vary based on the input provided, the data formats, prompts, and messages printed to the console when using your program should match those in the sample output files to receive full credit.
Satisfying all basic requirements perfectly, with no points deducted for any reason, would earn a maximum score of 100 out of 100 for this assignment.
Sample Output
Examples of the output for the console produced by my solution to this assignment are distributed together. Please see the attached file, “5_sample_output.txt”. This file shows what is shown to the user on the screen. There is also the output data file, of course, which contains the expected output if no error occurs. An example of the data output file is also distributed together (“5_sample_count_output.txt”).
Grading Criteria
This assignment will be graded on a 100 point scale. Your grade for this assignment will be based on a combination of factors, including:
- Correct functionality (e.g., Does your Python code do what it is supposed to do as outlined in the basic and/or advanced requirements?)
- Clarity of your solution (e.g., Did you solve the problem directly and efficiently? Or is your answer excessively complex and/or inefficient?)
- Coding style (e.g., Is your code readable with comments, meaningful variable names, and good whitespace/indentation?)
- Meets submission requirements (see below)
Seeking Help
For general questions about Python, please use the class forum on Canvas to seek assistance. For questions that are personal in nature or that would reveal a solution to the assignment, you can ask for help by email or during office. You can also contact our TA. However, please note that emailed questions will not receive an immediate response. It is likely that it will take 24-48 hours for me to respond.
Submitting Your Solution
Please Note: You must name the main python file for your assignment "assignment<number>_<EUID>.py". For example, for assignment 5, I would name my file “assignment5_SS0525.py” because my EUID is SS0525.
Using the wrong name for your file will be cost you points on your assignment grade. Please follow this requirement carefully!
Please submit your assignment via Canvas. You should submit an “ipynb” or “py” file.
Please note the "Late Assignments" policy on the course syllabus. It applies to this assignment and will be strictly enforced except under exceptional circumstances. See the course syllabus for details.
View Rubric
| Programming Assignments (100) | ||
|---|---|---|
| Criteria | Ratings | Pts |
| Correct functionality view longer description | 60 pts Full Marks All required functionalities are fully implemented.40 pts Proficient Some requirements are successfully implemented, but there are missing functionalities.20 pts No Marks An attempt has been made to implement the required functionalities, but the program is hardly working. | / 60 pts |
Clarity of solution view longer description | 20 pts Full Marks The required functionalities are well implemented in a simple and efficient manner.13.33 pts Proficient somewhat complex and inefficient.6.67 pts Needs Work The solution is excessively complex and inefficient. | / 20 pts |
Coding style view longer description | 20 pts Full Marks The solution can be easily understood by comments, all variable names are meaningful, and white space and indentation are used consistently.10 pts Proficient Some parts of the solution can be understood by comments, some variable names are meaningful, and some white spaces and indentation are used consistently.0 pts No Marks No comments, no meaningful variable names, and no consistent white spaces and indentation. | / 20 pts |
| Total Points: 0 |
Choose a submission type