{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip3 install penngrader --upgrade"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from penngrader.grader import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Autograder Setup\n",
"Enter your 8-digit PennID below:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"STUDENT_ID = 99999999"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following cell to initialize the autograder. This autograder will let you submit your code directly from this notebook and immidiately get a score.\n",
"\n",
"**NOTE:** Remember we store your submissions and check against other student's submissions... so, not that you would, but no cheating."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"grader = PennGrader(homework_id = 'CIS545_Spring_2019_HW1', student_id = STUDENT_ID)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1: Write an addition function!\n",
"Fill in the function body of `addition_function` that takes in two numbers and returns their sum."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"def addition_function(x,y):\n",
" return x + y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following cell to grade this question."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Correct! You earned 5/5 points. You are a star!\n",
"\n",
"Your submission has been successfully recorded in the gradebook.\n"
]
}
],
"source": [
"grader.grade(test_case_id = 'test_case_1', answer = addition_function)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 2: Now write a Class!\n",
"Add two class functions: `add_course` and `remove_course` that both take in a string representing a course ID."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"class Student:\n",
" def __init__(self, name = 'John', email = 'john@email', courses = []):\n",
" self.name = name\n",
" self.email = email\n",
" self.courses = courses \n",
"\n",
" def get_coures(self):\n",
" return self.courses \n",
"\n",
" def add_course(self, course):\n",
" self.courses.append(course)\n",
" \n",
" def remove_course(self, course):\n",
" self.courses.remove(course)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Correct! You earned 5/5 points. You are a star!\n",
"\n",
"Your submission has been successfully recorded in the gradebook.\n"
]
}
],
"source": [
"grader.grade(test_case_id = 'test_case_2', answer = Student)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 3: Finally, let's do some Pandas stuff!\n",
"\n",
"Run the following cell to load the dataset..."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" first_last_name | \n",
" grade | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Leonardo_Murri | \n",
" 100 | \n",
"
\n",
" \n",
" 1 | \n",
" Akshay_Grewal | \n",
" 65 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" first_last_name grade\n",
"0 Leonardo_Murri 100\n",
"1 Akshay_Grewal 65"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"students_df = pd.DataFrame([['Leonardo_Murri',100],['Akshay_Grewal',65]], columns = ['first_last_name','grade'])\n",
"students_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `.apply(...)` to keep only the last name in the `first_last_name` column."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" first_last_name | \n",
" grade | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Leonardo | \n",
" 100 | \n",
"
\n",
" \n",
" 1 | \n",
" Akshay | \n",
" 65 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" first_last_name grade\n",
"0 Leonardo 100\n",
"1 Akshay 65"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"students_df['first_last_name'] = students_df['first_last_name'].apply(lambda x: x.split('_')[0])\n",
"students_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, rename the `first_last_name` column to `first_name`. Make sure your final dataframe is called `student_df`."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" first_name | \n",
" grade | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Leonardo | \n",
" 100 | \n",
"
\n",
" \n",
" 1 | \n",
" Akshay | \n",
" 65 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" first_name grade\n",
"0 Leonardo 100\n",
"1 Akshay 65"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"students_df = students_df.rename(columns = {'first_last_name':'first_name'})\n",
"students_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the following cell to grade this question."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Correct! You earned 10/10 points. You are a star!\n",
"\n",
"Your submission has been successfully recorded in the gradebook.\n"
]
}
],
"source": [
"# Autograder cell: Test case #3\n",
"grader.grade(test_case_id = 'test_case_3', answer = students_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## View your score!\n",
"You made it this far, run the following cell to double check we stored all your scores correctly."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'pd' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgrader\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mview_score\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/usr/local/lib/python3.7/site-packages/penngrader/grader.py\u001b[0m in \u001b[0;36mview_score\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[0mgrades\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdeadline\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_daily_submissions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_score\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_deserialize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 52\u001b[0;31m \u001b[0mgrades_df\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgrades\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 53\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[0;31m# Extract student ID from [student_submission_id]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'pd' is not defined"
]
}
],
"source": [
"grader.view_score() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}