Skip to content

Instantly share code, notes, and snippets.

@simonthor
Created October 26, 2021 13:57
Show Gist options
  • Select an option

  • Save simonthor/9834c03e1a1ee9b7ff7277109cac9d6f to your computer and use it in GitHub Desktop.

Select an option

Save simonthor/9834c03e1a1ee9b7ff7277109cac9d6f to your computer and use it in GitHub Desktop.
Calculate grade for the electromagnetic theory course (TET) at KTH
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "6d546814-14c4-472d-bb65-ce60c4af6b06",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "8b2bf4fa-fd05-46d6-ae12-d78a0a525e41",
"metadata": {},
"source": [
"Main function:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "c01f8c6a-02c4-480b-a420-7c3176d576a2",
"metadata": {},
"outputs": [],
"source": [
"def tet_grade(exam_points: np.ndarray, quiz_points: np.ndarray):\n",
" \"\"\"Calculate the grade based on points from exams and points from quizzes. \n",
" Returns the total number of points and the grade.\"\"\"\n",
" quiz_bonus = 7 * np.sum(quiz_points) / np.sum((8, 8, 6, 5, 5, 10))\n",
" total_points = np.ceil(5 * (np.mean(exam_points) - 1 + np.prod(exam_points+1)**(1/len(exam_points))) + quiz_bonus).astype(int)\n",
" grade_limits = np.array([48, 50, 60, 70, 80, 90])\n",
" grades = ('F', 'Fx', *'EDCBA')\n",
"\n",
" for upper_limit, grade in zip(grade_limits, grades):\n",
" if total_points < upper_limit:\n",
" return total_points, grade\n",
" \n",
" return total_points, grades[-1]"
]
},
{
"cell_type": "markdown",
"id": "baba6e9d-ad5b-41d3-b888-d0082562dfb6",
"metadata": {},
"source": [
"Example use case:"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "7aec0760-ad36-4cf8-9ab3-a666f9db13c4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(90, 'A')"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"exam_points = np.array([10,9, 8,9, 8,6], dtype=int)\n",
"quiz_points = np.array([8, 8, 6, 5, 5, 10], dtype=int)\n",
"tet_grade(exam_points, quiz_points)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a03694a0-9834-4b42-b4f0-7d02dbe5f3fc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:uni]",
"language": "python",
"name": "conda-env-uni-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment