Reference no: EM133539200
Programming Fundamentals
Assessment - Python Console Programs
Objectives
This assessment item relates to the unit learning outcomes as in the Unit Profile.
Details
For this task, you'll be enhancing the capabilities of your Python Console Application, "Places to Visit," which you created in Assignment 1 Part A. This extension will involve showcasing your comprehension of list algorithms used for sorting and searching, along with skills in string formatting and file handling. It's important that your program generates accurate outcomes as required.
What you need to submit for this assignment.
The Python source codes:
You are advised to work on the assignment following incremental approach by making incremental progress on a weekly basis. Specifically for this assignment, your submission should consist of just the following two files. (Further details provided below.)
places_visit.py and place.py.
To get you started the source code for implementing the required functionalities is present in the files "places_vist.py" and "place.py". After you've finished developing all the programs and are prepared to submit, compile all source files into a singular zip file for submission. Please exclude your report from this zip file. Remember to submit in the zip format, not as a rar file. Accuracy in naming the files is
crucial.
o Ass2.zip
Similar to Part A, please include a report with your submission. This report should encompass the approximate duration taken to develop the programs, any challenges faced during the process, and
screenshots showcasing the generated output. (Utilize Alt-PrtScrn to exclusively capture the console window or dialog boxes; subsequently, paste them into your Word document.) Additionally, create a
comprehensive test plan that accounts for every potential scenario within the program. Ensure your test screenshots are annotated accordingly.
Assignment specification
You have already developed the "Places to Visit" application in Assignment 1 Part A. You can find the entire source code in the files "places_visit.py" and "place.py" both of which are available on the Moodle unit website within the Assessment Block.
The specification of Place class is as follows:
Class Name: Place
• Attributes:
o place_name (string), place_address (string), num_days (integer), total_cost (float)
• Methods:
o Constructor init (self, place_name, place_address, num_days, total_cost): Initializes a Place object attributes with the arguments passed to the
constructor (the init () method).
o String Representation str (self):
• Returns a human-readable string representation of the Place object.
• Format: "place_name at place_address, num_days days,
$total_cost".
o Equality Comparison eq (self, other): Compares the attributes of two Place objects for equality.
• Parameters: other parameter is a "Place" object
• Returns True if the objects have the same place_name values, otherwise
False.
o Less Than Comparison lt (self, other): Compares two Place objects based on their place_name attribute.
• Parameters: other parameter is a "Place" object
• Returns True if the calling object's attribute place_name is alphabetically less than other object's attribute place_name, otherwise False.
o Greater Than Comparison gt (self, other): Compares two Place objects based on their attribute place_name.
• Parameters: other is another Place object to compare.
• Returns True if the calling object's attribute place_name is alphabetically greater than other object's attribute place_name, otherwise False.
Add the following functionalities to the application:
Sort Places:
Write a function called sort_places() that takes a list of Place objects as input and sorts the list in ascending order of their names. The function should use the selection sort algorithm, that you learnt in week 7.
Add a new place:
Whenever a new place is added, the application must automatically arrange the places in alphabetical order by their names.
For instance, consider a list with the following data:
and if the user enters the following place:
The application should sort the list, and the output should be as follows:
Print places:
Upon selecting the "Print Places" option by the user, the list should be printed in a tabular format as depicted below:
You must update the print_places() function so that it prints the places list in tabular format. This concept was covered during the week 7 tutorial exercise in question 3, as demonstrated in the display_students(lst) function.
Delete a place:
When a user chooses to remove a place from the list, instead of requesting the user to provide the index for deletion, the user can now input the name of the place. The application will then search for the specified place within the list and proceed to delete it if located. If the place is not found in the list, a message will be displayed to inform the user about the absence of the specified place. The search operation must be performed without considering the character case. For instance, if a user searches for "New York," the search should also match "new york" or "NEW YORK" in a case-insensitive
manner. In this situation, the lower() and upper() methods of the string class would prove to be valuable.
You are required to employ the most optimal method for searching the list for the designated place. Keep in mind that the places list is organized in alphabetical order. Utilize this insight to select the suitable searching algorithm for implementation.
Below is the sample output:
Notice the user has entered the place name "taj mahal" all-in lower-case characters. If the user now prints the list of places the following table is displayed:
The search function overlooked the distinction in character case. The user entered "taj mahal" and the name of the place in the list was "Taj Mahal," the search function successfully identified and removed the place named "Taj Mahal."
If the place with the name entered by the user is not in the list the following message is printed:
Data persistence:
The application should have the ability to retain the inventory of planned travel destinations. For this purpose, each object is converted into a string representation, which is then saved on an individual line within the "planned_places.txt" file. The structure of each string adheres to the subsequent format:
Name| Address| Days| Cost Name| Address| Days| Cost Name| Address| Days| Cost Here's what each component represents:
• Name: The value of the place_name attribute of the place object (e.g., "Christ the Redeemer").
• Address: The value of place_address attribute of the place object (e.g., "Cristo Redentor, Rio de Janeiro, Brazil").
• Days: The number of days value of the num_days attribute of the place object (e.g., "2" indicating 2 days).
• Cost: The value of total_cost attribute of the place object (e.g., "300" indicating total cost is $300).
These components are separated by the vertical bar (or a pipe chacracter) (|) delimiter to maintain a consistent format for storing and later retrieving Place object information from the file. This character must not appear in the values of any of the instance attributes.
Create the write_file(lst, file_name) and read_file(lst, file_name) functions.
The lst parameter represents the list of place objects, and file_name is a string denoting the
filename to save the list of places. The write_file() function should save the list of place objects to the file_name file, while the read_file() function should retrieve the place objects from the same file. A similar implementation of these functions was done during the week 8 tutorial exercise, specifically question 3, involving a list of book objects. Modifications can be applied to adapt that implementation to cater to the requirements of this functionality.
Exception Handling:
The application should strive for consistent and reliable functionality. To achieve this, you must address the handling of the following two exceptions:
• ValueError
• FileNotFoundError
ValueError exception: This exception is triggered when a function receives an argument with the accurate data type but an incorrect value. In the context of the application, this exception can arise when the user provides values for the number of days and cost per day (while entering details for a new place). If the user inputs an incorrect value, this exception might be raised. To ensure smooth operation, you must address this exception by allowing the user to re-enter the value until a valid input is provided.
Attachment:- Programming Fundamentals.rar