CSP1150 Assignment 2 Semester 1, 2021 CSP1150 Assignment 2 Page 1 Programming Principles (CSP1150) Assignment 2: Individual programming project (“Would You Rather” Program) Assignment Marks: Marked...

You can fin the assignment attached bellow


CSP1150 Assignment 2 Semester 1, 2021 CSP1150 Assignment 2 Page 1 Programming Principles (CSP1150) Assignment 2: Individual programming project (“Would You Rather” Program) Assignment Marks: Marked out of 30, worth 30% of unit Due Date: 31 May 2021, 9:00AM Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fundamentals covered in the first half of the unit. Assignment Overview This assignment is themed around the conversational party game “Would You Rather”, in which people are asked to choose between two options in a hypothetical scenario. The options should be similar in nature and hard to choose between – either both desirable, both undesirable, or both mixed. Some example questions include “Would you rather be invisible, or be able to fly?”, “Would you rather be stuck on a broken ski lift, or in a broken elevator?”, and “Would you rather fight 1 horse-sized duck, or 100 duck-sized horses?” You are required to design and implement two related programs: • “admin.py”, a CLI program that allows the user to manage a list of “Would You Rather” questions which are stored in a text file. This program is referred to as the “Main Program” in the marking rubric. Develop this program before “wyr.py”. • “wyr.py”, a GUI program that uses the data in the text file to pose “Would You Rather” questions to the user and record their responses. This program is referred to as the “GUI Program” in the marking rubric. Develop this program after “admin.py”. The following pages describe the requirements of both programs in detail. Starter files for both programs are provided along with this assignment brief to help you get started and to facilitate an appropriate program structure. Please use the starter files. Please read the entire brief carefully, and refer back to it frequently as you work on the assignment. If you do not understand any part of the assignment requirements, contact your tutor. Be sure to visit the Blackboard discussion boards regularly for extra information, tips and examples. Semester 1, 2021 CSP1150 Assignment 2 Page 2 Pseudocode As emphasised by the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design for “admin.py”, but not “wyr.py” (pseudocode is not very well suited to illustrating the design of an event-driven GUI program). Furthermore, while your tutors are happy to provide help and feedback on your work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code. You will gain a lot more benefit from pseudocode if you actually attempt it before trying to code your program – even if you just start with a rough draft to establish the overall program structure, and then revise and refine it as you work on the code. This back-and-forth cycle of designing and coding is completely normal and expected, particularly when you are new to programming. The requirements detailed on the following pages should give you a good idea of the structure of the program, allowing you to make a start on designing your solution in pseudocode. See Reading 3.3 and the discussion board for further advice and tips regarding writing pseudocode. Write a separate section of pseudocode for each function you define in your program so that the pseudocode for the main part of your program is not cluttered with function definitions. Ensure that the pseudocode for each of your functions clearly describes the parameters that the function receives and what the function returns back to the program. Pseudocode for functions should be presented after the pseudocode for the main part of your program. It may help to think of the pseudocode of your program as the content of a book, and the pseudocode of functions as its appendices: It should be possible to read and understand a book without necessarily reading the appendices, however they are there for further reference if needed. The functions required in “admin.py” are detailed later in the assignment brief. The following pages describe the requirements of both programs in detail. Semester 1, 2021 CSP1150 Assignment 2 Page 3 Overview of “admin.py” “admin.py” is a program with a Command-Line Interface (CLI) like that of the programs we have created throughout the majority of the unit. The program can be implemented in under 200 lines of code (although implementing optional additions may result in a longer program). This number is not a limit or a goal – it is simply provided to prompt you to ask your tutor for advice if your program significantly exceeds it. Everything you need to know to develop this program is covered in the first 7 modules of the unit. This program should be developed before “wyr.py”. This program allows the user to manage a collection of “Would You Rather” questions that are to be stored in a text file named “data.txt”. Use the “json” module to write data to the text file in JSON format and to read the JSON data from the file back into Python. See Reading 7.1 for details of this. To illustrate the structure of the data, below is an example of the file content in JSON format: This example contains the details of two questions, stored in a list. The details of each question are stored in a dictionary consisting of five key-value pairs. The “option_1” and “option_2” keys contain strings of the two options of the question. The “mature” key contains a boolean value indicating whether the question is intended for mature audiences. The “votes_1” and “votes_2” keys contain integers representing the number of times each option has been selected – They are set to 0 when a question is added to the list, and are increased when the user chooses an option in “wyr.py”. If this file was to be read into a Python variable named data, then “data[1]” would refer to the entire dictionary containing the question about superpowers, and “data[1]['option_2']” would refer to the string of 'Be able to fly'. “data[0]['vote_1']” would refer to the integer of 3, etc. Understanding the structure of this data and how to interact with it is very important in many aspects of this assignment – in particular, you will need to understand how to loop through the items of a list and how to refer to items in a dictionary. Revise Module 3 and Module 7 if you are unsure about how to interact with lists and dictionaries, and see the Blackboard discussion board for further help. [ { "option_1": "Fight 1 horse-sized duck", "option_2": "Fight 100 duck-sized horses", "mature": true, "votes_1": 3, "votes_2": 5 }, { "option_1": "Be invisible", "option_2": "Be able to fly", "mature": false, "votes_1": 0, "votes_2": 0 } ] JSON Python and JSON use similar syntax, but boolean values start with a capital letter in Python. You do not need to worry about this – writing and loading data via the json module will handle it for you! Semester 1, 2021 CSP1150 Assignment 2 Page 4 Output Example of “admin.py” To help you visualise the program, here is a screenshot of it being used: Semester 1, 2021 CSP1150 Assignment 2 Page 5 Requirements of “admin.py” In the following information, numbered points describe a requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand the requirements or would like further information. The requirements are: 1. The first thing the program should do is try to open a file named “data.txt” in read mode, then load the data from the file into a variable named data and then close the file. ▪ The data in the file should be in JSON format, so you will need to use the “load()” function from the “json” module to read the data into your program. See the earlier page for details of the structure. ▪ If any exceptions occur (e.g. due to the file not existing, or it not containing valid JSON data), then simply set the data variable to be an empty list. This will occur the first time the program is run, since the data file will not exist yet. This ensures that you are always left with a list named data. ▪ This is the first and only time that the program should need to read anything from the file. After this point, the program uses the data variable, which is written to the file whenever a change is made. 2. The program should then print a welcome message and enter an endless loop which starts by printing a list of options: “Choose [a]dd, [l]ist, [s]earch, [v]iew, [d]elete or [q]uit.” and then prompts the user to enter their choice. Once a choice has been entered, use an “if/elif” statement to handle each of the different choices (detailed in the following requirements). ▪ This requirement has been completed for you in the starter file. 3. If the user enters “a” (add), prompt them to enter the two options of their question, then prompt them to enter “Y” or “N” to indicate if the question is intended for mature audiences. Place the details into a new dictionary with the structure shown earlier, and append the dictionary to the data list. Finally, write the entire data list to the text file in
May 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here