Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python This will involve practicing - Using for loops to iterate over the items in a list, potentially using enune rate() - Using append ()

python image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
This will involve practicing - Using for loops to iterate over the items in a list, potentially using enune rate() - Using append () to add elements into a new list - Using list methods sum () and len() to compute the average of a list - Using previously-written functions as helpers inside a new function Introduction In most courses, a course syllabus typically outlines 3-7 grade categories. Each category carries a percentage (weight) that it contributes to the final grade. For example, the percentages for some sample categories can be as follows - Participation 10% - Labsi 30% - Quizzes:30\% - Project 30% How can you store these values? You can store each category information in a dictionary, which captures a name of the category and its we ight (i e, the percentage of the total), and also stores grades that correspond to that category. "category": "n", "weighe" :0.0, "grades" : [1 You will also need to keep a "main" list to assemble the information for all categories: this list will store the record of each individual category (a nested list of dictionaries) Back to top Instructions Main Program Add the following option to the main program: elif opt 'T': total - get_total_grade (al1_grades, True) print (f"Current total is (tota1t. 2f)") In this lab, you will hard-code the information that is usually available in the sylabus and the corresponding grades to allow you to calculate the total grade - Add the following nested list to your code in main.py, before the while loop. - While you have the list in your clipboard, copy it into your test file as well, so that you can write tests using it. Functions To compute the course grade, you will need to write two new functions, get_grades () and get_total_grade(), and add them to functions. py. We have provided function stubs for you to use, which include documentation that you should read carefully - get_grades () should iterate through the provided nested list to extract all grades into a new nested list of lists - get_total_grade () should call get_grades() and get_list_avg() and then run a computation to get the total average grade (See LAB 7.22 forhints on how to write get_list_avg()) For example, in our main program, when we select the option T, we should see the following output: You selected option T to > show the total. PA average 85.008(4.25/5) CA average 82.17)(12.33/15) LA average 62.508(15.62/25,0) Qutz average 0.008(0.00/25) Project average 0.008(0.00/25) Current total 1532.20 Back to ton Computation example The following example will show you how we compute the final grade for the course using the weights and grades for those categories. The following information does NOT need to be printed out when the user chooses to Compute the grade The example below is to dematstrate the math behind the computation and to provide you with the information that you can use to debug your code. Make sure that you understand each step of the computation - ask questions if something about it is unclear: There are 5 categories in this example: PA=5.01(0.05) CA:15.04(0.15) QUIZ : 25.08(0.25) PROJECT : 25.08(0.25) Provided grades: PA grades [100.0,100.0,100.0,100.0,100.0,0.0,95.0]=7 elements CA grades [100.0,100.0,98.0,95.0,0.0,100.0]+6 elements LA grades [100.0,100.0,100.0,5.0,0.0,70.0]+6 elements Quiz grades [] Project grades We start out with a hard-coded list of categories, and grades in each of them. Sum of grades tor the PA category: 595.00 Sum of grades for the CA category: 493.00 Sum of grades for the LA category: 375.00 Sum of grades for the Quiz category: 0.00 Sur of grades for the Project category: 0.00 Average of the PA category: 595.00/7=85.00 Average of the CA category: 493.00/6=82.17 Average of the LA category: 375.00/6=62.50 Average of tho Quiz category: 0.00 Average of the Project category: 0.00 Then we calcuate the sums of grades for each category, and use that to calculate the average grade in each category. Average grade for the PA category: 85.00=0.05=4.25 Average grade for the CA category: 82.170.15=12.32 Average grade for the LA category: 62.500.2515.62 Average grade for the IA category: 62.500.25=15.62 Average grade for the Quiz category: 00.25=0.00 Average grade for the Project category: 00.25=0.00 Total Average grade =4.25+12.32+15.62+0.00+0.00=32.20 Finally we weight these average grades according to the weights the categories are defined to have. Rack to top Pseudo Code for calculating the average grade in the get_total_grade () set overall avg_sum to 0 call get grades (info_11st) to get the 118t only_grades cal1 get_1ist_avg() with the previous list as its input to get the 1ist avg grades for each category and its position in info 1ist: ( you might want to use enumerate () get the category average value from avg_grades (at the same index as it is in info_11st) get the category weight from the info_list compute the category grade: (category average value - (category weight / 100)) add the category gkade to avg tum if show ateps: print(f" (...)average(,.2f)s", end =" ") see the example in the instruetions print (f()/()) return the avg_oum Carefully read each function documentation - do not remove it, follow it (See LAB 7.22 for hints on how to write get_Llist_avg ()) Test your code Add the hard-coded example of the all_grades list to your test file. Use it to check that your function works correctly. Copy your as sert statements for get_list_avg () as well and add more assertions for your functions We suggest at least 3. This will involve practicing - Using for loops to iterate over the items in a list, potentially using enume rate() - Using append ( ) to add elements into a new list - Using list methods sum() and (en () to compute the average of a list - Using previously written functions as helpers inside a new function Introduction In most coursest a course syllabus typically outlines 3.7 grade categories. Each category carries a percentage (weight) that it contributes to the final grade. For example, the percentages for some sample categories can be as follows - Participation: 10% - Labs: 30\% - Quizzes 30\% - Project 30% How can you store these values? You can store each category information in a dictionary; which captures a nane of the category and its we ight (ie, the percentage of the total), and also stores grades that correopond to that category You will aiso need to keep a 'main" list to assemble the information for all categories: this list will store the record of each indlividuat category (a nested list of dictionaries) Back to 10R Instructions Main Program Add the following option to the main program. olif opt - 'T': total - get_total grade (ail_grades, True) ptint (f"current total ia (total: , 2t)") In this lab, you will hard-code the information that is usually avaiable in the syllabus and the corresponding grades to allow you to calculate the total grade - Add the following nested list to your code in main.py, belore the while loop. - While you have the list in your clipboard, cocy it into your test rile as well, so that you cah wite tests using it. Functions To compute the course grade, you will need to write two new functions, get _ grades () and get total_grade () , and add them to functions. py We have provided function stubs foryou to use, which include documentation that you should read carefuly - get_grades () should iterate through the provided nested list to extract all grades into a new nested list of lists - get_total_grade() should call get_grades () and get_list_avg() and then run a computation to get the total average grade. (See LAB7.2. for hints on how to write get_list_avg( )) For example, in our main program, when we select the option T, we should see the following output: You selected option T to > Show the total. PA average 85.00 s (4.25/5) CA average 82.178(12.33/15) th average 62.50%(15.62/25.0) Quiz average 0.005(0.00/25) Project average 0.004(0.00/25) current total 1332.20 Computation example The following example will show you how we compute the final grade for the course using the weights and grades for those categories. The following information does NOT need to be printed out when the user chooses to Compute the grade. The example beiow is to demonstrate the math behind the computation and to provide you with the information that you can use to debug your code Make sure that you understand each step of the computation-ask questions if something about it is unclear. There are 5 categoriegin this exampler PA+5.04(0.05) CA +15.08(0.15) 4L/25,04(0,25) Qurz +25,08(0.25) QUiz : 25.08(0.25) PROJECT : 25.08(0.25) Provided grades: PA grades [100.0,100.0,100.0,100.0,100.0,0.0,95.0]+7 elements CA grades [100.0,100.0,98.0,95.0,0.0,100.01,6 elements LA grades [100.0,100.0,100.0,5.0,0.0,70.0]+6 elements Quiz qrades [1 Project grades 1] We start out with a hard-coded list of categories, and grades in each of them. Sum of grades for the PA category: 595.00 Sum of grades for the CA category: 493.00 Sum of grades for the LA category: 375.00 Sum of grades for the Quiz Category: 0.00 Sum of grades for the Project category: 0.00 Average of the PA category: 595.00/7=65.00 Average of the CA category: 493.00/6=82.17 Average of the LA category: 375.00/6=62.50 Average of the Quiz category: 0.00 Average of the Project category: 0.00 Then we calcuate the sums of grades for each category, and use that to calculate the average grade in each category. Average grade for the PA category: 85.000.054.25 Average grade for the CA category: 82.17+0.15=12.32 Average grade tor the tiA category: 62.500.25=15.62 Average grade for the Qulz eategory: 0=0.25=0.00 Average qrade for the Quiz category: 00.25=0.00 Average grade for the Project category: 00.25=0.00 Total Average grade =4.25+12.32+15.62+0.00+0.00=32.20 Finally we weight these average grades according to the weights the categories are defined to have. Back to top Pseudo Code for calculating the average grade in the get_total_grade() Het overall avg sum to 0 call get grades (info 11st) to get the list only grades: call get_liat_avg () with the previous 11 st as its input to get the list avg grades for each category and its position in info list: + you might want to uye enumerate () get the category average value fron avg grades (at the same index as it is in info list) get theycategory weight from the info 1 ist compute the category grade: (category average vaiue * (category weight / 100)) add the category grade to avg_sum If ahow steps: print (f(..)average(..,26)", end =" " & see the examplo in the instructions print (f" (.)/()". return the avg sum Carefully read each function documentation - do not remove is, follow it (See LAB 7.22 for hints on how to write get_list_avg ( )) Run the computation example against the given pseudocode to better understand it (wak through each step of the computation example and see where it is done in the pseudocode) Add the hard-coded example of the all_grades list to your test file. Use it to check that your function works correctly. Copy your assert statements for get_List_avg() as well and add more assertions for your functions We suggest at least 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago