Hi, I was wondering how much this would cost!
Figure 1: A portion of the data in midterm.csv. Question 1 [35 points] In the year 202X, in a major university on the North American continent, students in an introduc- tory programming class, COMPUT 2202, underwent a midterm examination. This midterm exam consisted of several different topics, drawn from a large pool of topics, where each topic had several questions. The data for this imaginary midterm exam can be found (in part) in the file midterm.csv, a file of comma-separated values. By opening this file in a text editor (or more preferably, spreadsheet software such as Numbers or Excel), you will see the data in tabular format. See Figure 1 for an example of how it might look. Each column in the file represents the midterm exam answers of an individual student (except the first column, which gives the row titles). In particular, the first row gives the student number, the second and third rows give the number of topics that student did not complete (due to lack of time, e.g.,), and the fourth column gives the ID of the individual who graded their exam. The rest of the rows are divided into topics and questions for those topics. Each topic begins with a row called ”Topic X”, where X is the topic number (from 1 to 13). An X in that row for any student’s column means that that student was given that topic during the exam. The rows that follow the topic row are the questions for that topic. Each topic has a certain number of questions (between 1 and 6). An X in a question row for any student’s column means that that student answered that question correctly. In this question, we will write various functions that calculate statistics of the data (average, etc.), as well as plot these statistics to the screen using Matplotlib, in the file midterm.py. Examples of how the plots should look can be seen in Figure 2. 3 Figure 2: Examples of how the plots should look. Before we get started, note that several functions to process the data, as listed below, are already defined for you. It is up to you to decide where and when to use them in your own code. read csv(filename): Takes a filename of a .csv file as parameter and returns the list of lists for the data in that file. count x in row(row): Takes a list as parameter and returns the number of x and X in that list. get row for question(data, topic, question): Takes the midterm data as list of lists and topic and question number, and returns the row (list) corresponding to that question. get num questions in topic(data, topic): Takes the midterm data as list of lists and topic number, and returns the number of questions in that topic. get num students(data): Takes the midterm data as list of lists, and returns the total number of students who sat for the midterm. get num students for topic(data, topic): Takes the midterm data as list of lists and topic number, and returns the total number of students who were given that topic during the exam. get topics for student(data, student col index): Takes the midterm data as list of lists and a column index for a particular student, and returns the list of topics that that student was given during the exam. Basic functions (30 points) plot num students per topic(data) The first plot we will make relates to the number of students who were given each topic during the exam. For example, say 100 students were given topic 1, while 95 students were given topic 5. We will display this data in a pie chart. The function to make a pie chart is as follows: plt.pie(data, labels=categories) 4 where data is a list of percentages, each percentage in the range [0.0, 1.0], corresponding to the per- centage of students that were given a topic relative to the total number of students, and categories is a list of labels (e.g., ‘Topic 1’, ‘Topic 2’, etc.), where each element at position i of categories refers to the percentage at position i of data. Make sure to give your pie chart a title, and then show it to the screen. The next calculation we will make is the average per topic. For example, if all students who took topic 1 did very well on all the questions in topic 1, then topic 1 will have a high average. We will calculate the exact value by writing three functions as follows. get average of question(data, topic, question) Given a particular topic and question number, calculate and return the average for that question, which is simply the number of correct answers for that question (for all student columns) divided by the total number of students who were given that topic. get average of topic(data, topic) Given a particular topic, calculate the average for each question in that topic, then calculate and return the average of all those question averages. plot topic averages(data) Display the average for each topic in a bar chart, where each bar corresponds to the average of a different topic, and show it to the screen. Make sure to give titles for your plot, x-axis, and y-axis. Also, make sure that the topic number (1, 2, ..., 13) shows underneath each bar (under the x-axis). You can do so by calling the plt.xticks function, passing a list of integers (topic numbers from 1 to 13) as argument. We will next calculate the student averages for the entire exam. get student average(data, student col index) Given a particular column index (referring to an individual student), calculate their average for the exam. Note that you will have to go through each topic, check if the student was given that topic, and if so, count the number of questions in that topic, and count how many of those questions they got correct. Do this for each topic, keeping count as you go, and when done, you can take the number of questions they got correct and divide it by the total number of questions they were given. If they were given 0 questions, instead return the None value. get student averages(data) Return a list containing the average for each student (by calling your function above for every student, but excluding None values). 5 plot student averages(data) Display the averages for all students in a histogram, and show it to the screen. Make sure to give your histogram a title. Make the x-axis range from 0.0 to 1.0 (you can again use the plt.xticks function, providing a list of values of increments of 0.1). A histogram can be produced in Matplotlib by calling plt.hist(data, bins=x), where data is the list of percentages between 0 and 1 (e.g., student averages), and x is the number of ‘bins’, or separate bars, to display in the histogram. Use 20 bins for your histogram. Finally, we will write a function to determine the so-called ‘hard’ questions on the exam. get hard questions(data) Go through every question of every topic, calculate the average for that question, and check if the average is less than 0.4. Return a list of strings of the format ‘TxQy’, where x and y correspond to the topic/question number whose average was less than 0.4. E.g., if topic 2 question 5 and topic 8 question 2 were hard, then the returned list should be [‘T2Q5’, ‘T8Q2’]. Additional functionality (5 points) For the remaining 5 points of this question, you are encouraged to make a plot to display some other interesting characteristic of the data. The requirements to obtain the 5 points are as follows: • The plot must be of a different type than the ones above (i.e., not a pie chart, bar chart or histogram). • The plot must show some interesting characteristic of the data for which it was necessary to perform some computation and iteration (not a simple statistic like total number of students, or total number of questions per topic). If you are unsure if your idea qualifies, please ask on Piazza, as it will not be possible to make your case after submission if you are unhappy with the grade for these 5 points. One example of an interesting statistic is the average of students per grader. There were five graders in total and each student was assigned to one grader. It may be interesting to see some kind of plot that shows the difference in student averages from grader to grader. 6 Question 2 [40 points] I want to be the very best, Like no one ever was. To catch them is my real test, To train them is my cause! In this question we will write a Pokemon Battle Simulator. Pokemon is a popular game in which ‘Pokemon Trainers’ battle each other using the ‘Pokemon’ they have captured. Each Pokemon has a name, a type relating to their abilities (water-based, electric-based, fire-based, etc.), and a list of attack moves (e.g., ‘tail swipe’, ‘mega punch’, etc.), amongst other attributes. A battle between Pokemon Trainers is turn-based, where each Pokemon uses one attack move on the opposing Pokemon, the move being chosen by the Pokemon Trainer. Instead of using an attack move, a Pokemon Trainer can also decide to use an item on their Pokemon (e.g., a health potion, which increases their hit points, or HP), or switch to another one of their Pokemon for the rest of the battle. If the hit points (HP) of a Pokemon reaches 0, they faint, and the Pokemon Trainer must send out another one of their Pokemon. The battle ends when a Pokemon Trainer has no more Pokemon left (i.e., they have all fainted). Other important things to know include: • After a Pokemon wins a battle, they gain experience points. When enough experience points have been gained, the Pokemon reaches a new level of strength. • Certain types of Pokemon are strong against some types, and weak against others. For example, Pokemon of electric type are strong against ground type Pokemon, but weak against flying type Pokemon. Thus, in battle, their moves will be more and less effective, respectively. The code for the battle simulation itself is already given to you in the file battle.py. Your job is to define the classes that this battle simulation depends on, as listed below. Note that two other files besides battle.py are also provided to you: • element types.py: Defines an Enum called ElementType for the different possible element types (to be used for