© 2019 Chris Olsen and Arizona Board of Regents CIS 345 – Business Information Systems Development - II Assignment: Movie Trivia Learning Outcomes 1.1. Code and design a Decorator to wrap a function....

refer to file for instructions


© 2019 Chris Olsen and Arizona Board of Regents CIS 345 – Business Information Systems Development - II Assignment: Movie Trivia Learning Outcomes 1.1. Code and design a Decorator to wrap a function. 1.2. Implement multiple generator functions to save memory. 1.3. Implement functions to perform basic functionality. Program Overview Your task is to build a movie trivia program. A text file has been provided with 11 questions and answers. The application will present users with a prompt consisting of the question number and a movie character. The user’s task is to then enter the movie title of the movie that character was portrayed in. The application will keep asking questions until all questions from the file have been asked. After all questions the user will be shown their earned score out of 11 total possible points. The application will award points for answers that are mostly correct in the event there are minor spelling issues. See the sample output for an example. Note: The application logic is very short so you can focus on learning how to implement these advanced features (functions, generator functions, and decorators). © 2019 Chris Olsen and Arizona Board of Regents Sample Output © 2019 Chris Olsen and Arizona Board of Regents Instructions & Requirements • Create a PyCharm Project using standard naming convention • Download questions.txt data file and place in project folder. • Create a new python file and name it trivia.py. Requirements – the following must be coded in your program: 1) Design a decorator that will decorate our generator function that generates question number. Recall the decorator function has within a wrapper function. The decorator function will create a variable that is assigned the generator and then you will use this variable within your wrapper by calling next on it (e.g. next(gen) ). The wrapper will return a formatted string that is the prompt containing ‘Question # :’ the # will be the number you get by calling the next function on your generator function described in #2 below. I recommend importing wraps from functools Hint – Very important to define the variable hold the #2 generator object in the decorator scope not wrapper and also don’t forget about passing arguments to wrapper such as *args, **kwargs. Note this decorator differs from our example because it is a generator so instead of func() we are doing next(gen) which will call your question_number function and yield back a number (might want to store it). 2) Create a generator function, question_number, that will generate the question number and yield one number at a time. Question numbers must start at 1 and increment up by 1 for each question. There are only 11 questions in the text file at this time, but your generator should be able to count up to any number because in the future questions may be added to the file. Decorate this function with the decorator you created in #1 above. 3) Define a second generator function, get_questions, that accepts a file path to a file. The generator will open the file to read each question and answer in the text file. The generator must yield 1 line at a time. You must clean the data in each line from the file by stripping out excess spaces. 4) Create a normal function, grade_question, that accepts the user entered answer and the real answer, determines if its right, and returns the earned points. At least 70% matching is considered correct, 1 point, and under is 0 points. We will use something new to compare the two strings for close match. You must import difflib and then you can execute the below function that will return a ratio/percentage of how closely string a matches string b each other. Syntax below: ratio = difflib.SequenceMatcher(None, a, b).ratio() Note: a and b represent the strings you want to compare. Replace with your names. © 2019 Chris Olsen and Arizona Board of Regents 5) Program Logic: Use get_questions to access questions.txt file to get questions and answers from the file. Reset point total to nothing. 6) Display application title and instructions 7) Display all questions, prompting the user for their answer, and grade the question and add points to a total. Repeat for all questions. You’ll need to split() each line read from the file splitting on a comma as that is separating the question from the answer. Don’t be tricked into thinking this is a csv file because the file extension is .txt. 8) Finally print the score of points earned out of the total. Exit program Assignment-specific Submission Instructions (if any) All CIS 345 submissions must adhere to standards detailed in the following documents available on course website, for full credit. • CIS 345 Assignment Submission Instructions • CIS 345 Programming Conventions • CIS 345 Commenting Guide General Grading Criteria 1. Assignments will be scored out of 30 points. 2. Assignments will be graded on source code AND output, with the emphasis on the code. Grading Criteria Points Imports are correct and Title with instructions are displayed 2 Customer decorator accepts a generator, creates object for the generator, has a wrapper that gets numbers and formats the question prompt to include the question text from the file. 5 question_number generator function counts up from 1 to infinity and is decorated by custom decorator 5 get_questions generator opens file passed in and yields all stripped lines 5 grade_question compares entry with answer and awards a point if the entered answer is 70% matching or more. Returns point value. 5 Program logic adheres to specified requirements above 5 Style and Standards CIS 345 Programming Conventions are followed Names and file names are accurate conform to PEP 8 File has name, class, assignment number, and class time written on Line 1. All variable names are descriptive. 3
Oct 09, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here