Assignment 8 - ldkvd/CS101L GitHub Wiki
Welcome to the CS101L Wiki!
Weighted Grades
We’re going to work on something that is important to all students, grade weighting. Our program will allow the user to enter 2 types of grades; Tests and Programs. Each of our scores is assumed to be out of 100, so we only need the user's score. The tests are 60% of a student's grade, while the assignments are 40%. In order to calculate the final score, we multiply the mean score of the tests by 0.6 and add it to the mean of assignments multiplied by 0.4.
When we display scores we will also show them the low, high, mean, and standard deviation of their tests and assignments. The mean is the average. To calculate the mean you would sum all the values and divide by the number of values. If the values we want a mean for are 5, 8, 4, 9 then the mean is mean =(5+8+4+ 9) / 4. In this case, our mean is 6.5.
The standard deviation is calculated by taking each value and subtracting the mean and squaring the value. Divide the sum of those values by the number of values, and take the square root of that result.
Some Additional items to think about.
- When entering scores, it must be a valid number (afloat)and cannot be less than zero. (we’ll allow scores greater than 100 however)
- If you try to remove a score and it is not in the list of scores, then warn the user that it could not be removed.
- If there are no scores for one of the categories, then you can’t calculate the avg, std, etc. instead display n/a for those values.
Answer:
The image above is the source code part 1/5.
The image above is the source code part 2/5.
The image above is the source code part 3/5.
The image above is the source code part 4/5.
The image above is the source code part 5/5.
This image above provides the output 1/3.
This image above provides the output 2/3.
This image above provides the output 3/3.
In this code, multiple functions are defined and called. Functions allow for the same piece of code to run multiple times. It reduces clutters, complexity, and duplication of codes. It breaks down a large program into smaller, easy-to-manage components. We can call one statement (the function), rather than writing the same code over and over for each time we want to add, remove, clear a list, etc. Within some of the functions, try and except blocks are used to account for possible value errors such as a score being less than 0 or a value (mean, min, max) not existing at all.
The while loop allows the program to run until the user inputs a valid that quits the program. Within the while loops, if-else statements are used to allow the user's choice to be compared to the options from the menu. If the user's choice is equal to an option from the menu, the respective function will be called and run to execute the desired output.
When the function add_test() or add_assignment() is called, within the try block, the user is asked to enter a score. If the score is less than 0, the except block will execute. If the score is valid, then the score will be added to the list. When the function remove_test() or remove_assignment() is called, the user is asked to enter a score. If the score is in the list, then the score will be removed. Else, a message will be printed to warn the user that the score was not found to be removed. When the function clear_test() or clear_assignment() is called, the list will be completely cleared. When option 'd' is selected, the function display_scores() will be called. This function will display the number of tests/assignments, the minimum score, the max score, the average score, and the standard deviation.