DAM101 Programming and Algorithms DAM101 Final Assessment The final assessment for this module consists of 5 Questions. Please read each of the questions carefully and you should attempt ALL of the questions.
DAM101 Programming and Algorithms DAM101 Final Assessment The final assessment for this module consists of 5 Questions. Please read each of the questions carefully and you should attempt ALL of the questions. The marking rubric can be seen on the assessment page on Canvas.
Submission Requirements Code should be submitted in the .ipynb format. Submit one code file per question (4 code files total, 1 for each of the questions 2-5). Report should be submitted in the .pdf format. Documentation Requirements Comments and docstrings should be concise. Comments and docstrings should have a consistent format throughout the solutions. Comments should explain the function of the code written. Each function must include a docstring that explains the purpose of the function, parameters and the return value. Variable and function names must be descriptive and follow a consistent naming style, but maximum 25 characters. Tasks
- As you complete Questions 2 to 5 below, maintain notes on your design decisions, challenges, and solutions. Refine and submit these as a single reflective report (maximum 1000 words).
For each of Questions 2 to 5, your report must clearly address the following:
i) Explain the reasoning behind the coding decisions you made. This may include the choice of algorithms and data structures, structure of the code or other design decisions.
ii) Reflect on any difficulties faced while completing the question. Explain how these were identified and resolved.
iii) Your report must be supported with evidence, including code snippets and screenshots. For example, these could show the errors encountered or unexpected results.
iv) You must reference relevant video lectures and the textbook to justify or contextualise your coding decisions. For video lectures, include the week number, lecture number and approximate timestamp. For example:
“I decided to use the len() function to find the number of elements in the list (block 4, lecture 3, 1:35-2:35).”
Use an appropriate academic referencing style for textbook citations. For example:
“I decided to use f-strings approach for string formatting (Speight, 2020, p. 59).”
You should include references both in the text and also in a reference list at the end.
[16 marks]
- i) Write a function that takes a sequence of integers from user input using the function in appendix A and stores them in a tuple.
ii) Write a function that takes a tuple of integers ‘my_tuple’ and an integer ‘k’, and returns the element whose difference from k is the smallest. If two values are equally close, return both.
iii) Write the code to test the code in parts i) and ii). Use 5 as the value of ‘k’.
iv) Document the code in parts i), ii) and iii) as detailed in the Documentation Requirements.
[8 marks]
- In this task you will need to use the insertion sort algorithm code from Block 8 Lecture 4.
i) Modify the insertion sort algorithm to sort strings in descending order and print the state of the list after every swap is performed.
ii) Write all of the output produced in part i) into a text file named ‘sorting_strings.txt’.
iii) Test the code with the following list of numbers:
[‘by’, ‘the’, ‘just’, ‘this’, ‘work’, ‘sad’, ‘ant’, ‘ten’, ‘trick’, ‘bus’]
iv) Document the code in parts i), ii) and iii) as detailed in the Documentation Requirements.
[8 marks]
- In this task you need to take input from a text file and process it.
i) Create a function that reads the contents of the file called ‘text.txt’ using the function in Appendix B.
ii) This function should then check if any of the strings in the text file contain duplicate characters. The function should return a tuple of strings that contain the duplicate characters.
iii) Write code to test the function and you can use the following text for the ‘text.txt’:
Donec vitae magna rutrum ipsum mattis auctor. Pellentesque ultrices elit malesuada massa tincidunt venenatis. Mauris neque diam, fringilla vel nulla in, euismod posuere mauris. Ut molestie odio eget lorem luctus, quis consequat sem maximus. Praesent at molestie nibh. Proin sed hendrerit orci.
Vestibulum venenatis ipsum sit amet pretium maximus. Etiam nisi ipsum, vehicula a placerat ac, viverra sit amet mi. Donec tristique justo pharetra, placerat sapien ac, sollicitudin lectus. In ut porta sem.
iv) Document the code in parts i), ii) and iii) as detailed in the Documentation Requirements.
[8 marks]
- You are given the following dictionary:
Cookware Appliances Utensils Frying Pan 24.99
Microwave 89.99
Spoons Set 5.50
Saucepan 19.99
Toaster 29.99
Fork Set 6.50
Wok 29.99
Blender 49.99
Knife Set 12.99
i) Write a program that stores the data above using three dictionaries. Print the categories and items within them in an easy to read format. After printing, display a message confirming that all food categories have been successfully created.
ii) Write a function called ‘find_average’, which takes the category name as an argument and returns the average (mean) price of items in this category.
iii) Write a function called ‘add_product’, which takes ‘category’, ‘name’ and ‘price’ as arguments and adds the appropriate entry in the dictionary.
IV) Write the code to test the function in part ii) using the following two names: ‘Utensils’, ‘Containers’ (wrong category). Write code to test the function in part iii) choosing appropriate values.
v) Document the code in part i) as detailed in the Documentation Requirements.