-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-2.qmd
84 lines (61 loc) · 3.35 KB
/
project-2.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "Programming Project 2"
---
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(readxl)
assignments <- read_excel("assessment_schedule.xlsx") %>%
mutate(formatted_date = format(due_date, "%A, %B %d, %Y"))
```
Programming Projects are to be submitted to [gradescope](https://www.gradescope.com/courses/934148).
**Due date: `r assignments %>% filter(assessment == "Programming Project 2") %>% pull(formatted_date)` at 9pm**
In this programming project you will implement a number of Python functions to validate or transform values conditionally. Make sure you follow the provided [style guide](style.html) (you will be graded on it!). You are allowed to use `round()`, `str()` and `len()`, but other than that you are **not** allowed to use any other built-in method or function from any Python library.
Also make sure you check the [Academic Integrity](academic-integrity.html) and [Common Gradescope Errors](gradescope-errors.html) pages.
Name the program `grades.py`. Make sure that gradescope gives you the points for passing the test cases.
## `letter_grade()`
This function determines a letter grade ("A", "B", and so on) based on a float argument representing a percentage grade.
It returns a letter grade based on the following rules:
- Greater or equal to 90, return "A"
- Greater or equal to 80, return "B"
- Greater or equal to 70, return "C"
- Greater or equal to 60, return "D"
- Anything less, than 60 return "E" but greater or equal to 0
- If argument is negative or greater than 100, return "X"
## `pass_or_fail`
This function determines if a student passed or failed a class, based on their final letter grade.
Letter grades equal to "A", "B", "C", or "D" are passing grades (`"Pass"`).
## Calculate percentage -- `point_grade` function
This function calculates a percentage grade based on a `score` and `total_points`. It calculates the percentage grade by dividing score by total_points, and multiplies result by 100. It returns the calculated percentage as a float rounded at two decimals
## Calculate final grade -- `get_grade_results` function
This function takes two `score` and `total_points`, and it calls the previous functions you've written -- DO NOT recalculate percentage of grade, letter grade, etc. in this function. You are required to call the other functions. It returns a message similar to: `Your grade is 92.34 (A - Pass)` or `Your grade is 35.78 (E - Fail)`
## Test Cases
```{python}
#| eval: false
#| echo: true
def main():
# test letter_grade function
assert letter_grade(90) == "A"
assert letter_grade(80) == "B"
assert letter_grade(70) == "C"
assert letter_grade(60) == "D"
assert letter_grade(59) == "E"
assert letter_grade(-59) == "X"
assert letter_grade(110) == "X"
# test pass_or_fail function
assert pass_or_fail("B") == "Pass"
assert pass_or_fail("E") == "Fail"
assert pass_or_fail("ABCD") == "Error"
# test point_grade function
assert point_grade(0, 100) == 0.0
assert point_grade(100, 100) == 100.0
assert point_grade(45, 80) == 56.25
assert point_grade(37, 40) == 92.5
# test get_grade_results function
assert get_grade_results(0, 100) == "Your grade is 0.0 (E - Fail)"
assert get_grade_results(45, 80) == "Your grade is 56.25 (E - Fail)"
assert get_grade_results(37, 40) == "Your grade is 92.5 (A - Pass)"
main()
```